Results 1 to 14 of 14

Thread: QSqlQuery not working

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2010
    Posts
    26
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question QSqlQuery not working

    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:

    Qt Code:
    1. int ProductsForm::categoryIdByName(const QString& name)
    2. {
    3. QSqlQuery categories = QSqlQuery(model->database());
    4. categories.prepare("SELECT id FROM Categories "
    5. "WHERE name=:name)");
    6. categories.bindValue(":name",name);
    7. categories.exec();
    8. if(categories.size()==-1)
    9. {
    10. qDebug() << "error";
    11. return 1;
    12. }
    13. 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.
    Last edited by BrainStorm; 15th August 2010 at 00:59. Reason: spelling corrections

Similar Threads

  1. QSqlQuery
    By yasher in forum Qt Programming
    Replies: 2
    Last Post: 23rd July 2010, 14:25
  2. QSqlquery
    By codeman in forum Qt Programming
    Replies: 10
    Last Post: 4th June 2009, 12:57
  3. what is going on a QSqlQuery?
    By mismael85 in forum Qt Programming
    Replies: 2
    Last Post: 26th June 2008, 13:35
  4. QSqlQuery problem
    By MarkoSan in forum Qt Programming
    Replies: 14
    Last Post: 14th January 2008, 22:50
  5. QSqlQuery error
    By skuda in forum Qt Programming
    Replies: 2
    Last Post: 2nd November 2007, 08:43

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.