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] How to get comboBox data instead of index with registerfield
Qt 6.11 is out! See what's new in the release blog

[Solved] How to get comboBox data instead of index with registerfield

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

    Hi,

    I'm making a GUI app with a QWizard and QWizardPages structure.

    In the first page I have a combobox (cb_info1) with some items:

    @cb_info->AddItem("A");
    cb_info->AddItem("B");
    cb_info->AddItem("C");@

    Then I register it using: registerField("Info_combo", cb_info);

    And finally in page2, I want to show which option was selected(if A, B or C) showing the info on a label:

    @myLabel->setText(field("Info_combo").toString());@

    If option A was selected, myLabel should show (or at least is want I am trying to): A
    But instead of that it shows '0' which I suppose its the index of the item selected of the Combobox.

    How can I make that the label shows "A" instead of the index ? I saw there is a itemtext property but u have to pass the index which I don't know or I don't see how to do it.

    Thank you.

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

      Hi,

      IIRC, you can use the currentText property when registring your field. Then you should get the text rather that the index.

      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
      • R Offline
        R Offline
        roseicollis
        wrote on last edited by
        #3

        That is something I've already tried but I just get errors cause I don't know how to put it really... I'm trying with registerField("Info_combo", cb_info, cb_info->currentText()) but there is no way to make it work

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

          try
          @
          registerField("info_combo", m_ui->cb_info, "currentText", "currentTextChanged");
          @

          1 Reply Last reply
          0
          • R Offline
            R Offline
            roseicollis
            wrote on last edited by
            #5

            Yeah!!! It worked Andre, thank you so much! I was trying to put currentText and currentTextChanged as if they were functions, not Strings.

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

              Technically, they are not strings, but const char* :)

              Glad you got it to work.

              It is time IMHO that these signatures also get a more modern twin taking a function pointer instead.

              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