I'm stucked at this problem since a very long time ( about one day or more ), I just can't find what's wrong! it looks so simple and until now everything in the project did work fine, relational tables, and etc, well, I isolated it in a function, may I explain first, I've loaded a QComboBox with a QSqlQueryModel with this query: "SELECT name FROM Categories", ok. Then I need to insert the id of the selected item in another table (for using as relation), I made this function:
int ProductsForm::categoryIdByName(const QString& name)
{
categories.prepare("SELECT id FROM Categories "
"WHERE name=:name)");
categories.bindValue(":name",name);
categories.exec();
if(categories.size()==-1)
{
qDebug() << "error";
return 1;
}
return cate
int ProductsForm::categoryIdByName(const QString& name)
{
QSqlQuery categories = QSqlQuery(model->database());
categories.prepare("SELECT id FROM Categories "
"WHERE name=:name)");
categories.bindValue(":name",name);
categories.exec();
if(categories.size()==-1)
{
qDebug() << "error";
return 1;
}
return cate
To copy to clipboard, switch view to plain text mode
I call it with QComboBox::currentText(), BUT, as you see my concern there, query size aways return -1, no item! i've tried a lot of other querys, like "SELECT * FROM Categories", but nothing! I'm SURE the database, tables and items where created and inserted respectively, the program did work fine until this, I hope you guys can enlight-me and help me kick off this meaningless error. thanks in advance, sorry my bad english.
Bookmarks