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 foreach on all QComboBoxitems ?
Forum Updated to NodeBB v4.3 + New Features

How to foreach on all QComboBoxitems ?

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 7.1k 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.
  • D Offline
    D Offline
    deleted28
    wrote on last edited by
    #1

    I want to get all QStrings from a QComboBox, but do not know
    how to manage the model stuff.
    Started trial& error on the following code:

    @ foreach (QString str, myQComboBox )
    {
    qDebug() << _str;
    }@

    or:

    @ for( int i = 0;i < myQComboBox->count(); i++)
    {
    qDebug() << myQComboBox->itemText(i);
    }
    @

    both approaches are not OK

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

      Hi,

      What do you mean by not ok ?

      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
      0
      • D Offline
        D Offline
        deleted28
        wrote on last edited by
        #3

        sorry, not ok means a bunch of errors starting with :

        /usr/include/QtCore/qglobal.h:2371: error: 'QComboBox*' is not a class, struct, or union type
        typename T::const_iterator i, e;

        for this variant:

        @ foreach (QString str, myQComboBox )
        {
        qDebug() << _str;
        }
        @

        the second (for loop) works.

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

          foreach requires a container class (e.g. QList, QVector, etc.), QComboBox is not such a class

          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
          1
          • D Offline
            D Offline
            deleted28
            wrote on last edited by
            #5

            doesn't the model/ view framework of QComboBox provide such container and if so, how to access ?

            1 Reply Last reply
            0
            • musimbateM Offline
              musimbateM Offline
              musimbate
              wrote on last edited by
              #6

              From the "doc":http://qt-project.org/doc/qt-5/qcombobox.html
              it seems there is no such method that returns a container.You might need to use the old school for loop and the count method of your combobox.

              Hope this helps.

              Why join the navy if you can be a pirate?-Steve Jobs

              1 Reply Last reply
              1

              • Login

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