Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 137661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T07:08:29+00:00 2026-05-11T07:08:29+00:00

I need a method helping me, to reach variables named like comboBox1, comboBox2 etc

  • 0

I need a method helping me, to reach variables named like ‘comboBox1’, ‘comboBox2’ etc each by each in a loop. I’d like to change code like:

//proceed comboBox1 //proceed comboBox2 //proceed comboBox3 //proceed comboBox4 //proceed comboBox5 //proceed comboBox6 

Into:

for (int i = 1; i < numberOfBoxes; i++) {     //proceed comboBox(i) } 

I tried to find somthing like ‘eval’, but google didn’t give anything matching. I also tried preprocessing the name with operator ## but it seems there’s no way to put current integer value to the macro.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T07:08:30+00:00Added an answer on May 11, 2026 at 7:08 am

    The simplest solution is to put them all in an array and iterator over that:

    // I've made up a type, but you get the idea. std::vector<ComboBox *> combos; combos.insert(comboBox1); combos.insert(comboBox2); combos.insert(comboBox3); combos.insert(comboBox4); combos.insert(comboBox5); combos.insert(comboBox6); 

    Now you can iterate over combos. The main problem is that c++ doesn’t have reflection. So you can’t generated a string at runtime and get the address of an object or function like you can in some other languages.

    EDIT: I just saw that you are using Qt. In that case, you should use:

    QList<T> qFindChildren ( const QObject * obj, const QString & name ); 

    or

    QList<T> qFindChildren ( const QObject * obj, const QRegExp & regExp); 

    This lets you get a list based on runtime generated names. For example:

    QList<QComboBox *> combos = qFindChildren(ui, QRegExp('combo[0-9]+')); 

    then you can just iterate over that!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know downcasting like this won't work. I need a method that WILL work.
My university has quite a lot files (like past papers etc) which I need
I need method which works like addImage , but only for a canvas context.
I need a method for a user to quickly enter info using a Handheld
I need a method to return a random string in the format: Letter Number
I need a method for adding business days in PHP. For example, Friday 12/5
I need a method that takes a linkedlist as a parameter and return true
I need a method that creates an empty clone of an object in a
I need a method in JavaScript to escape all characters which are not (
I need a method to redirect my Mac's audio output to a different computer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.