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 can I pass data of QComboBox between classes?

How can I pass data of QComboBox between classes?

Scheduled Pinned Locked Moved Unsolved General and Desktop
qt 4.8.5qcombobox
6 Posts 3 Posters 2.5k Views
  • 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 roseicollis
    #1

    An easy question I hope:

    I'm using Qt 4.8.5 ... I have a combobox with a text shown and a data value and I want to know that data value in another page. I know I can use registerfield("field_name", my_cb, "currentIndex","currentIndexChanged"); (I'm using QWizardPAges as classes) to pass the index from one class to another one. My question is... can I do the same with the data? I found the itemData property but nothing like a currentDataChanged or something like that (for version 4.8.5).

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

      Well, you can connect the activated(int index) signal to a slot. In this slot you can get the item associated with this index calling itemData() and then you emit another signal and pass the item to that signal. Everyone interested in this item can connect to this signal.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      R 1 Reply Last reply
      0
      • jsulmJ jsulm

        Well, you can connect the activated(int index) signal to a slot. In this slot you can get the item associated with this index calling itemData() and then you emit another signal and pass the item to that signal. Everyone interested in this item can connect to this signal.

        R Offline
        R Offline
        roseicollis
        wrote on last edited by
        #3

        @jsulm yes yes, I know I can do it this way. I could even make a Q_PROPERTY for it if I need to write on it BUT my question was if there wasn't an easy wway using registerfield();

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

          Hi,

          Do you mean get the text of the selected item of the combo box ?

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

          R 1 Reply Last reply
          0
          • SGaistS SGaist

            Hi,

            Do you mean get the text of the selected item of the combo box ?

            R Offline
            R Offline
            roseicollis
            wrote on last edited by roseicollis
            #5

            Hi @SGaist long time since last one! hehe

            No, for current text i know I can use currentText and currentTextChanged. I need the data, the one you store when you do something like my_combobox->addItem("Monday", 12); Where 12 is the data and this, is what I want to pass to another class. Hope it is more clear now, if not let me know it please.

            Thank you!

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

              Yes, it's clearer.

              In that case I'd create a subclass of QComboBox with a property that would return content of data.

              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

              • Login

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