Results 1 to 7 of 7

Thread: sqlite - driver not loaded

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2012
    Location
    Romania
    Posts
    22
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default sqlite - driver not loaded

    Hello,

    I'm using Qt to work with a sqlite database but I have an error. If I try to declare the handler for the QSqlDatabase object as a pointer I get the error: Driver not loaded. So if I use

    Qt Code:
    1. db = QSqlDatabase::addDatabase("QSQLITE");
    To copy to clipboard, switch view to plain text mode 

    everything is ok but if I'm trying to use a pointer

    Qt Code:
    1. db = new QSqlDatabase;
    2. db ->addDatabase("QSQLITE");
    To copy to clipboard, switch view to plain text mode 

    I get the error that the Driver is not loaded. Anyone has any idea why the second case doesn't work?

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,318
    Thanks
    315
    Thanked 870 Times in 857 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: sqlite - driver not loaded

    Have you deployed the SQL drivers into the appropriate subdirectory of your app directory, as specified in the docs?

  3. #3
    Join Date
    Apr 2012
    Location
    Romania
    Posts
    22
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: sqlite - driver not loaded

    Well, I have no problem with the SQL driver for the first case (when I don't use a pointer) so I haven't changed the location for the SQL driver. But because I use a pointer you say I might need to have the dll file in the folder of my application?

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: sqlite - driver not loaded

    The second code snippet doesn't do anything with the return value of addDatabase().

    Quote Originally Posted by Saurian View Post
    Well, I have no problem with the SQL driver for the first case (when I don't use a pointer)
    The first case also uses the initialized database connection returned by addDatabase() and stores it in the local variable.

    Cheers,
    _

  5. #5
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: sqlite - driver not loaded

    Quote Originally Posted by Saurian View Post
    I get the error that the Driver is not loaded. Anyone has any idea why the second case doesn't work?
    To elaborate on what @anda_skoa said:

    QSqlDatabase::addDatabase is a static method and you are not operating on the db instance you think you are, because static member methods don't have a "this" pointer and thus do not operate on an instance of an object.

    QSqlDatabase::addDatabase returns a QSqlDatabase instance, but you're not assigning that to a variable, so your attempt to add the database connection is essentially a no-op. You are creating a database instance by calling QSqlDatabase::addDatabase, then you throw away the result, hence the no-op.

    The instance you allocated via "new QSqlDatabase()" is still an invalid database object since you have only invoked its default constructor.

    If you *must* create a QSqlDatabase instance on the heap, try something like this:

    Qt Code:
    1. QSqlDatabase *db = new QSqlDatabase(QSqlDatabase::addDatabase("QSQLITE"));
    To copy to clipboard, switch view to plain text mode 

    Good luck.

Similar Threads

  1. QT & SQLite - driver not loaded
    By Tomasz in forum Newbie
    Replies: 5
    Last Post: 15th June 2014, 11:59
  2. Driver not loaded with sqlite
    By SIFE in forum Qt Programming
    Replies: 2
    Last Post: 9th September 2013, 12:40
  3. Driver not loaded (sqlite) at Ubuntu
    By Simplevolk in forum Newbie
    Replies: 1
    Last Post: 8th February 2013, 14:50
  4. Android / necessitas: SQLITE error ("Driver not loaded")
    By Al_ in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 28th August 2011, 15:06
  5. SQlite driver not loaded error
    By ibergmark in forum Installation and Deployment
    Replies: 2
    Last Post: 17th March 2008, 01:09

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
  •  
Qt is a trademark of The Qt Company.