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 ?

teukkam
  • 4,267
  • 1
  • 26
  • 35
mehmetozer
  • 848
  • 6
  • 14
  • 30

2 Answers2

5

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

teukkam
  • 4,267
  • 1
  • 26
  • 35
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.

secretgenes
  • 1,291
  • 1
  • 19
  • 39