As I understood, QComboBox
can hold a text (i.e. the name) and data (i.e. an object). My QComboBox
should store QSizeF
's, while showing nice names. Hence I would like to do something like this:
void fillComboBox() {
ui->combobox->addItem("big", QVariant(QSizeF(600,400)));
ui->combobox->addItem("medium", QVariant(QSizeF(300,300)));
ui->combobox->addItem("small", QVariant(QSizeF(100,200)));
}
The problem is, that QVariant
takes a QSizeF
by const
reference and not by value/move. After return, the reference will therefore dangle.
What is the correct way to do that? If I've a type MyClass
, thus a custom class and not a Qwhatever, how would I use QVariante
with that?
Note: of course I could create the QSizeF
on the heap - however, I would need to take care of the memory which I try to avoid. This is eventually the reason for my question.