Results 1 to 2 of 2

Thread: [SOLVED] database opened .. database not open

  1. #1
    Join Date
    Feb 2011
    Posts
    3
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Exclamation [SOLVED] database opened .. database not open

    so i was one day programming using Qt
    i tried creating a class file name 'database' and added 3 methods
    'createConnection', 'execute' and 'close'

    in my main.cpp

    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include "mainwindow.h"
    3. #include "../library/database.h"
    4.  
    5. int main(int argc, char *argv[])
    6. {
    7. QApplication a(argc, argv);
    8. database myDb;
    9. myDb.createConnection("QSQLITE","../healthdex/resources/recipes.sqlite");
    10. myDb.execute("SELECT * FROM recipe");
    11. myDb.close();
    12.  
    13.  
    14. MainWindow w;
    15. w.show();
    16.  
    17. return a.exec();
    18. }
    To copy to clipboard, switch view to plain text mode 

    for the first try it worked! then after clicking the debug button again
    it returned errors

    Qt Code:
    1. Database Opened
    2. QSqlQuery::exec: database not open
    3. There is an error QSqlError(-1, "Driver not loaded", "Driver not loaded")
    To copy to clipboard, switch view to plain text mode 

    i included the files in my project so you can see the 'database' class that i created
    healthdex.zip


    Added after 27 minutes:


    tried adding ..

    Qt Code:
    1. if(database::querier.exec(query, this->db)){
    To copy to clipboard, switch view to plain text mode 
    and
    Qt Code:
    1. if(database::querier.exec(query, database::db)){
    To copy to clipboard, switch view to plain text mode 

    in line 26 but it returned 'no matching function for call...'

    fixed it by adding

    Qt Code:
    1. database::querier = QSqlQuery::QSqlQuery(database::db);
    To copy to clipboard, switch view to plain text mode 

    above the

    Qt Code:
    1. if(database::querier.exec(query)){
    To copy to clipboard, switch view to plain text mode 

    Last edited by kapitanluffy; 23rd February 2011 at 19:59.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: [SOLVED] database opened .. database not open

    One needs to use QSqlDatabase::addDatabase() to load the database driver first.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. [QSqlQuery] Problem with not open database
    By xkazielx in forum Newbie
    Replies: 11
    Last Post: 1st September 2013, 20:32
  2. Replies: 9
    Last Post: 20th May 2010, 09:55
  3. QSqlQuery::exec: database not open
    By newtowindows in forum Qt Programming
    Replies: 8
    Last Post: 29th October 2009, 08:48
  4. Best way to open database
    By estanisgeyer in forum Qt Programming
    Replies: 2
    Last Post: 8th February 2008, 05:18

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.