Use a QSqlQueryModel and set it via QComboBox::setModel() to your combobox. Then you can get all the information of the query through the normal index approach.
Use a QSqlQueryModel and set it via QComboBox::setModel() to your combobox. Then you can get all the information of the query through the normal index approach.
Could you please give me an example of how to do this.... I've been messing about for hours now and I don't seem to be getting anywhere.
Thanks for your time and trouble![]()
setModel method of QComboBox is reimplemented, it's argument is QAbstractItemModel
do as Lykurg suggested you to do, and simple use setModel to set QSqlQueryModel model for combo box
check the documentation of QSqlQueryModel if you do not know which method use to set the query
My schedule makes my cry
My works makes my laugh
My life makes... oh...no....
Splatify (21st February 2011)
Ok so this is what I have done so far:
Qt Code:
QString querystring = "SELECT u.UserID, f.FileName, f.FileLocation, s.Size, s.Finished FROM users u JOIN stats s ON s.UserID = u.UserID JOIN file f ON s.FileID = Q.FileID WHERE u.UserID = 1"; QSqlQuery modelquery; modelquery.exec(querystring); model->setQuery(modelquery); model->setHeaderData(0, Qt::Horizontal, "UserID"); model->setHeaderData(1, Qt::Horizontal, "File Name"); model->setHeaderData(2, Qt::Horizontal, "File Location"); model->setHeaderData(3, Qt::Horizontal, "Size"); model->setHeaderData(4, Qt::Horizontal, "Finished");To copy to clipboard, switch view to plain text mode
so then i have to update my combobox with this model. I can do this by doing:
Qt Code:
ui->ComboBox->setModel(model);To copy to clipboard, switch view to plain text mode
However this puts the UserID in the combo box. How do i show the Filename in the combo box and then how do i use the model so when a particular file is selected within the combobox, the file location of the selected file is used in another function.
Thanks for your time and trouble![]()
wiz (16th January 2012)
See the modelColumn property or simply query the filename as the first element in your query. Further make the model a member variable then you can access it in the slot and get the value by using QSqlQueryModel::record().
Splatify (21st February 2011)
Ok so now i have this:
Qt Code:
ui->QuizBox->setModel(model); ui->QuizBox->setModelColumn(1);To copy to clipboard, switch view to plain text mode
I'm still unsure of how to use this model. Could you give me some example code of how to use the model when an item is selected in the combobox and a button is pressed.
Thanks very much
Bookmarks