Accessing QVariant of QComboBox
I'm wanting to use a QComboBox as a sort of data storage for my application. It's not a large ammount of data, and I think this would be the easiest way to not be constantly reading from the database file. This little snippit shows what I'm trying to do.
Code:
dataList << "D1" << "D2" << "D3";
ui
->ShowDate
->insertItem
(0,
QDate(query.
value(2).
toInt(), query.
value(0).
toInt(),
query.value(1).toInt()).toString(("MMMM d, yyyy")), dataList);
I know how to access the text with
Code:
ui->lineEdit->setText(ui->ShowDate->currentText());
but how do I access the QVariant?
I'm new to not only Qt, but c++ as well, so a small snippit showing how to put, say dataList[0] into a lable...
Code:
ui->label->setText(<however to get dataList[0] in here>);
Qt version 4.5
Re: Accessing QVariant of QComboBox
Quote:
I know how to access the text with
Qt Code:
1
ui->lineEdit->setText(ui->ShowDate->currentText());
but how do I access the QVariant?
I dont think QLineEdit has QVariant...
Quote:
I'm new to not only Qt, but c++ as well, so a small snippit showing how to put, say dataList[0] into a lable...
ui->label->setText(dataList.at(0));
Re: Accessing QVariant of QComboBox
QComboBox::itemData().
You can also use "dynamic properties" on every widget.
Re: Accessing QVariant of QComboBox
@aamer4yu: I think you misunderstood my question. The QVariant I was talking about was attached to my QComboBox. I was trying to get that data into the lineEdit and/or label.
@wysota: Thank you so much. Looking into the QComboBox::itemData() and Qt::UserRole got me access to data... and no code snippit needed, I used your info to discover how to do it on my own.
You have been officially thanked.. :)