How can I pass data of QComboBox between classes?



  • 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).


  • Moderators

    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.



  • @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();


  • Lifetime Qt Champion

    Hi,

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



  • 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!


  • Lifetime Qt Champion

    Yes, it's clearer.

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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.