Results 1 to 4 of 4

Thread: QSQLITE driver is driving me nuts!

  1. #1
    Join Date
    Jun 2008
    Posts
    8
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Red face QSQLITE driver is driving me nuts!

    hi there;

    I have a problem connecting to a sqlite 3.5.9 using QT 4.5 in a fedora 10 machine.
    when i try the following code:
    Qt Code:
    1. db = QSqlDatabase::addDatabase("QSQLITE");
    2. if (db.isValid())
    3. std::cout<<"db is valid!"<<endl;
    4. db.setHostName("localhost");
    5. db.setDatabaseName("feed");
    6. if (db.open()){
    7. std::cout<<"db opened"<<endl;
    8. cout<<"drivers are : "; // just to open all the available drivers
    9. QStringList r = QSqlDatabase::drivers();
    10. for (int i=0;i<r.size();i++)
    11. std::cout<<((QString)r.at(i)).toStdString()<<endl;
    12.  
    13. QString txt="select * from item_table";
    14. query.exec(txt);
    15. if (query.isValid() && query.isActive()){
    16. std::cout<<"query is valid and active"<<endl;
    17. }
    18. else{
    19. std::cout<<"in error: "<<query.lastError().text().toStdString()<<endl;
    20. }
    To copy to clipboard, switch view to plain text mode 

    the output of that code is:

    Qt Code:
    1. db is valid!
    2. db opened
    3. drivers are : QSQLITE
    4. QSqlQuery::exec: database not open
    5. in error: Driver not loaded Driver not loaded
    To copy to clipboard, switch view to plain text mode 

    as you cabn see. both methods : db.isValid() and db.opn() return true. showing the available drivers using QSqlDatabase::drivers() prints QSQLITE

    BUT when i try to execute the select statement - on the valid and existing table item_table - it throws to me :"QSqlQuery::exec: database not open"
    and the query.lastError().text() prints : "Driver not loaded" twice

    what am i missing here??? can anybody help Me PLS??

  2. #2
    Join Date
    Mar 2008
    Posts
    141
    Thanks
    10
    Thanked 9 Times in 9 Posts

    Default Re: QSQLITE driver is driving me nuts!

    HI,

    what if you try a full path in setDatabaseName()?

  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QSQLITE driver is driving me nuts!

    Hi, the problem is that you use query without setting the opened database to that query, so the QSqlQuery is invalid. Use
    Qt Code:
    1. if (db.open())
    2. {
    3. QSqlQuery query;
    4. //...
    5. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jun 2008
    Posts
    8
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Talking Re: QSQLITE driver is driving me nuts!

    Quote Originally Posted by Lykurg View Post
    Hi, the problem is that you use query without setting the opened database to that query, so the QSqlQuery is invalid. Use
    Qt Code:
    1. if (db.open())
    2. {
    3. QSqlQuery query;
    4. //...
    5. }
    To copy to clipboard, switch view to plain text mode 
    Thanks a lot Sir; the error saying "Driver not Loaded" has disappeared Like Magic

    thanks again!

Similar Threads

  1. QSQLITE driver issue
    By b1 in forum Qt Programming
    Replies: 6
    Last Post: 17th May 2009, 09:18
  2. Replies: 1
    Last Post: 7th July 2008, 20:13

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.