PDA

View Full Version : from sqlquery to qstringlist



ditsikts
23rd October 2011, 21:11
try to read a sqlquery, save it into a qstringlist and set it to combobox.
pass compile but combobox is empty.


QStringList cblist;
QSqlQuery query;
query.prepare("SELECT lastname FROM employeestuf");
query.exec();
while(query.next())
{
if (query.isValid())
cblist<<query.value(0).toString();
}

ui->comboBox->addItems(cblist);

ChrisW67
23rd October 2011, 22:34
The errors are obvious in your posted code... you should learn to use the tools you already have to find it. Have you single stepped through the code in your debugger? Have you checked the error returns from QSqlQuery::exec() and QSqlQuery::lastError()? Have you looked at the database that is actually created? What tables exist? What tables are you trying to use in your code?

udaypratapyati
23rd July 2012, 14:39
Hi all,

I am facing similar problem.

I have create the application using forms (ui file) using qtcreator.
when i try to add a list to the combo-box, its added but not displaying.

I have cross verified for the existance of the entries in the combo-box with count() and displays the
correct count i inserted and also it gives the correct values which fetched and displayed on terminal.

Can any one help me out with a method to display the same list in the application.

Thanks,
Uday Pratap

tokimay
4th February 2016, 16:39
QSqlQuery *query = new QSqlQuery("select "+filed_name+" from "+table_name);
while(query->next())
{
combobox.addItem(query->value(0).toString());
}

anda_skoa
4th February 2016, 18:18
Why on earth did you post that?

Not only is it wrong on many levels, it is what the original poster already had without any of the bad things.

Cheers,
_