PDA

View Full Version : How to get comboBox data instead of index with registerfield



roseicollis
2nd February 2015, 09:52
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 ?

Thank you.

anda_skoa
2nd February 2015, 11:13
Look at the documentation of registerField:
for a QComboBox the default property is currentIndex.

Look at the properties of QComboBox and at the third argument of registerField.

Cheers,
_

adutzu89
2nd February 2015, 12:52
You can get the current item's text in a QComboBox with currentText();

roseicollis
2nd February 2015, 15:21
Look at the documentation of registerField:
for a QComboBox the default property is currentIndex.

Look at the properties of QComboBox and at the third argument of registerField.
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


You can get the current item's text in a QComboBox with currentText();
Yes I know, but with that you need to pass the index and I want it throw registerField() property :) But can't find the way :(

anda_skoa
2nd February 2015, 17:03
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


Look at the documentation more closely.
You will find that its method documentation, like the one for registerField(), has information about the type of each argument.

In the case of registerField's third argument it is "const char*", which, as you a C++ developer will know, is the type of C string literal.
Which, as you know, is a sequence of characters within double quotes.

Looking again at the documentation, you will find that each QObject based class has a section describing its properties.

Cheers,
_

roseicollis
3rd February 2015, 11:35
Oh! I see what you mean now. Didn't notice about that, Thanks!