Question

I am really new to Qt and I have a little question for you. I am trying to work on ComboBox and when I add items to a combobox an integer like;

 combobox->addItem(class.value); // class.value is an integer

It just adds a symbol to the combobox (*, / or ? ) How can I solve this little problem ?

Was it helpful?

Solution

Try combobox->addItem(QString::number(class.value));

OTHER TIPS

Use QVariant . Advantage of using QVariant over QString::number() is you can convert data of any type to any other type.

int to string

 QVariant(32).toString(); //assuming calss.value to be int

in your case it will be

combobox->addItem(QVariant(class.value).toString());

float to a string

QVariant(3.2).toString();

string to a float:

 QVariant("5.2").toFloat();

it is that easy.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top