Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. how to create array of Qcombobox
Forum Updated to NodeBB v4.3 + New Features

how to create array of Qcombobox

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 1.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • TheCipo76T Offline
    TheCipo76T Offline
    TheCipo76
    wrote on last edited by TheCipo76
    #1

    i need to create an array of Qcombobox

    i've tried to create different combobox

    comboBox_Origine_1
    comboBox_Origine_2
    comboBox_Origine_3

    now i have to populate the comboboxes with a loop ( i = 0 to 10)

    how can i point to anyone?

    comboBox_Origine_+i->additem("ESTERNA");
    

    this is the errors displayed:

    /Users/matteomissora/EasyGest/inserisciarticolo.cpp:13: error: use of undeclared identifier 'comboBox_Origine_'

    /Users/matteomissora/EasyGest/inserisciarticolo.cpp:13: error: member reference type 'QString' is not a pointer; did you mean to use '.'?

    /Users/matteomissora/EasyGest/inserisciarticolo.cpp:13: error: no member named 'additem' in 'QString'

    i've tried both with

    comboBox_Origine_ & QString::number(i)->additem("ESTERNA");
    

    errors:

    /Users/matteomissora/EasyGest/inserisciarticolo.cpp:14: error: use of undeclared identifier 'comboBox_Origine_'

    /Users/matteomissora/EasyGest/inserisciarticolo.cpp:14: error: member reference type 'int' is not a pointer

    i've to convert "i" index to a pointer??

    JonBJ 1 Reply Last reply
    0
    • TheCipo76T TheCipo76

      i need to create an array of Qcombobox

      i've tried to create different combobox

      comboBox_Origine_1
      comboBox_Origine_2
      comboBox_Origine_3

      now i have to populate the comboboxes with a loop ( i = 0 to 10)

      how can i point to anyone?

      comboBox_Origine_+i->additem("ESTERNA");
      

      this is the errors displayed:

      /Users/matteomissora/EasyGest/inserisciarticolo.cpp:13: error: use of undeclared identifier 'comboBox_Origine_'

      /Users/matteomissora/EasyGest/inserisciarticolo.cpp:13: error: member reference type 'QString' is not a pointer; did you mean to use '.'?

      /Users/matteomissora/EasyGest/inserisciarticolo.cpp:13: error: no member named 'additem' in 'QString'

      i've tried both with

      comboBox_Origine_ & QString::number(i)->additem("ESTERNA");
      

      errors:

      /Users/matteomissora/EasyGest/inserisciarticolo.cpp:14: error: use of undeclared identifier 'comboBox_Origine_'

      /Users/matteomissora/EasyGest/inserisciarticolo.cpp:14: error: member reference type 'int' is not a pointer

      i've to convert "i" index to a pointer??

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @TheCipo76
      You cannot access a variable name with anything like your comboBox_Origine_+i.

      • If you stick to three distinct variables, you must address them as their full variable name, adjusting your code to reference the right one as appropriate.

      • If instead you create an array/list of comboboxes, they won't have their own variable names, and you can address the desired one via arrayOfCombos[i].

      • Finally you could give each a setObjectName(QString("comboBox_Origine_") + QString.number(i)) (maybe not exact syntax for adding a number to a string, I'm not C++, you can figure that one) and then use "find widget by object name" to address the desired one.

      1 Reply Last reply
      5
      • TheCipo76T Offline
        TheCipo76T Offline
        TheCipo76
        wrote on last edited by
        #3

        ok, i understand that i can't access to combobox as i tried..
        this in my problem..

        i have to populate not 3 but 10 combobox with a loop as i wrote
        this is the reason for which I would want use a cycle..

        i don't find with google search any example how to create and use an array of combobox

        JonBJ 1 Reply Last reply
        0
        • TheCipo76T TheCipo76

          ok, i understand that i can't access to combobox as i tried..
          this in my problem..

          i have to populate not 3 but 10 combobox with a loop as i wrote
          this is the reason for which I would want use a cycle..

          i don't find with google search any example how to create and use an array of combobox

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @TheCipo76
          That's because there isn't anything special to say about "an array of combobox". It's just an array. You know how to handle that, don't you?

          # create 100 comboboxes
          QComboBox *array[100];
          for (int i = 0; i < 100; i++)
          {
              array[i] = new QComboBox;
              layout->addWidget(array[i]);
          }
          
          # access a particular combobox out of the array
          QComboBox *aComboBox = array[50];
          
          1 Reply Last reply
          1
          • TheCipo76T Offline
            TheCipo76T Offline
            TheCipo76
            wrote on last edited by
            #5

            ok i understand..

            thank you very much

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Hi,

              Using a QVector<QComboBox *> might be a better idea for easier handling.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              4

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved