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.6k 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.
  • ? Offline
    ? Offline
    A Former User
    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
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #4

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

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        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
        • ? Offline
          ? Offline
          A Former User
          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);
          }@

          1 Reply Last reply
          0
          • ? Offline
            ? Offline
            A Former User
            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
            • ? Offline
              ? Offline
              A Former User
              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

              1 Reply Last reply
              0
              • ? Offline
                ? Offline
                A Former User
                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
                • ? Offline
                  ? Offline
                  A Former User
                  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....

                  1 Reply Last reply
                  0
                  • ? Offline
                    ? Offline
                    A Former User
                    wrote on last edited by
                    #11

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

                    1 Reply Last reply
                    0
                    • ? Offline
                      ? Offline
                      A Former User
                      wrote on last edited by
                      #12

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

                      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