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. [SOLVED =)]ComboBox Qstring but need an int or GLenumb
Qt 6.11 is out! See what's new in the release blog

[SOLVED =)]ComboBox Qstring but need an int or GLenumb

Scheduled Pinned Locked Moved General and Desktop
12 Posts 2 Posters 7.5k 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.
  • M Offline
    M Offline
    mariusmssj
    wrote on last edited by
    #1

    Hey everyone once again I got a question to ask,

    I got a combobox with 10 values:
    "Picture of the combobox values here":http://i.imgur.com/lYo9A.jpg

    As you can see it's a list of OpenGL primitives that are GLenumb.

    I got this function:
    @void MainWindow::on_cmbx_primatives_currentIndexChanged(const QString &arg1)
    {
    GLFrame->RenderThread.setPrimitiveType(arg1);
    primL = arg1;
    }@

    This sets the PrimitiveType value in the rendering class but clearly it's just a string and not an integer. Is it possible to set an additional value to a comboxbox argument for example the Text would be as an additional value that I could pass???
    "Since you can set comments and other additional values":http://i.imgur.com/jYYrB.jpg

    @GL_POINTS : but contain 0x0000@

    thank you

    1 Reply Last reply
    0
    • A Offline
      A Offline
      AcerExtensa
      wrote on last edited by
      #2

      You can populate your combobox with "this":http://qt-project.org/doc/qt-4.8/qcombobox.html#addItem function:
      @void void QComboBox::addItem ( const QString & text, const QVariant & userData = QVariant() )@

      userData can be all you want...

      God is Real unless explicitly declared as Integer.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mariusmssj
        wrote on last edited by
        #3

        Thank you, it seems i am doing something wrong
        @ui->cmbx_primatives->addItem(const QString("Test"), const QVariant & userdata = QVariant(const int(0x0000)));@

        1 Reply Last reply
        0
        • A Offline
          A Offline
          AcerExtensa
          wrote on last edited by
          #4

          Try this:
          @ui->cmbx_primatives->addItem("Test", QVariant::fromValue<int>(0x0000));@

          God is Real unless explicitly declared as Integer.

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mariusmssj
            wrote on last edited by
            #5

            yep AcerExtensa that worked like a charm =]
            but how do I access the integer value from arg1 so I could pass it to the render class?

            1 Reply Last reply
            0
            • A Offline
              A Offline
              AcerExtensa
              wrote on last edited by
              #6

              use
              @void currentIndexChanged ( int index )@
              signal instead one with QString.

              your slot will be when like this:
              @void MainWindow::on_cmbx_primatives_currentIndexChanged(int index)
              {
              primL = ui->cmbx_primatives->itemData(index).toInt();
              GLFrame->RenderThread.setPrimitiveType(primL);
              }@

              God is Real unless explicitly declared as Integer.

              1 Reply Last reply
              0
              • M Offline
                M Offline
                mariusmssj
                wrote on last edited by
                #7

                AcerExtensa your magic worker, is it possible to access the name of the index instead of the number.
                I tried @QString arg1 = ui->cmbx_primatives->itemText(index).toStdWString();@ but that's wrong

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  AcerExtensa
                  wrote on last edited by
                  #8

                  @QString arg1 = ui->cmbx_primatives->itemText(index);@

                  should be enough... or:

                  @QString arg1 = ui->cmbx_primatives->currentText();@
                  it will return text of currently selected item

                  God is Real unless explicitly declared as Integer.

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    mariusmssj
                    wrote on last edited by
                    #9

                    Yep that worked right away.

                    Well I removed all the values from the comboxbox in the Qt creator interface and the program crashed.
                    "The program has unexpectedly finished."

                    So then I just randomly added an item to the combo box and it worked again. Why's that?

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      AcerExtensa
                      wrote on last edited by
                      #10

                      Maybe you're trying to access items or userData before there is any items in combobox? Sounds pretty like that....

                      God is Real unless explicitly declared as Integer.

                      1 Reply Last reply
                      0
                      • M Offline
                        M Offline
                        mariusmssj
                        wrote on last edited by
                        #11

                        Once again AcerExtensa thank very much =] all my problems are now solved!!!

                        1 Reply Last reply
                        0
                        • A Offline
                          A Offline
                          AcerExtensa
                          wrote on last edited by
                          #12

                          You are welcome! Please add "[SOLVED]" to the topic subject.

                          God is Real unless explicitly declared as Integer.

                          1 Reply Last reply
                          0

                          • Login

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