2

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 ?

2 Answers 2

5

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

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.