QT & SQLite - driver not loaded[Win7 XP mode failed too]

本博客解决了一个在使用QT和SQLite进行数据库读取时遇到的错误问题。通过安装额外的QtSQLite驱动和调整代码路径,成功解决了数据库无法打开的错误。同时分享了在特定操作系统(如Windows XP Pro SP3)上遇到的加载问题,以及通过回退到旧版SQLite DLL解决的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  1. http://www.qtcentre.org/threads/32585-QT-amp-SQLite-driver-not-loaded

    QT & SQLite - driver not loaded

    Hello!

    I'm trying to read from SQLite database. I've wrote simple function:

    Qt Code:
              
    1. void MainWindow :: odczytajBazeSQL ( )
    2. {
    3. QSqlDatabase :: addDatabase ( "QSQLITE" );
    4.  
    5. bdb. setDatabaseName ( "/test.db" );
    6. bdb. open ( );
    7.  
    8. QSqlQueryModel *queryModel = new QSqlQueryModel;
    9. queryModel ->setQuery ( "SELECT * FROM t1", bdb );
    10.  
    11. ui ->tableView ->setModel (queryModel );
    12. }
    To copy to clipboard, switch view to plain text mode 

    test.db is a simple database with one table t1. When I'm trying to read with code above I get error:

    Qt Code:
              
    1. QSqlDatabase : QSQLITE driver not loaded
    2. QSqlDatabase : available drivers :
    3. QSqlQuery :: exec : database not open
    To copy to clipboard, switch view to plain text mode 

    Normally I'm using sqlite3 to create and use databases. What should I do to make it work?

    thanks in advance
    best regards
    Tomasz
  2. #2
    wysota's Avatar
    wysota 
    wysota is offline Master of Zen           
    Nokia Certified Qt Developer
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    28,434
    Thanks
    3
    Thanked 4,110 Times in 3,960 Posts
    Qt products
    Qt3  Qt4 Qt5  Qt/Embedded
    Platforms
    Unix/X11  Windows  Maemo/MeeGo
    Blog Entries
    4
    Wiki edits
    10

    Default Re: QT & SQLite - driver not loaded

    QSqlDatabase: available drivers:
    You don't seem to have any Qt sql drivers installed. Maybe you need to install some additional packages for your distribution.
    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.

  3. The following user says thank you to wysota for this useful post:

    Tomasz (21st July 2010)
  4. #3
    Tomasz 
    Tomasz is offline Intermediate user
    Join Date
    Jul 2010
    Location
    Poland
    Posts
    184
    Thanks
    70
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4  Qt/Embedded
    Platforms
    Unix/X11  Windows

    Default Re: QT & SQLite - driver not loaded

    I've copied compilled driver (it wasn't there), I've change my code to:

    Qt Code:
              
    1. QSqlDatabase bdb = QSqlDatabase :: addDatabase ( "QSQLITE" );
    2.  
    3. bdb. setDatabaseName ( "./test.db" );
    4. ok = bdb. open ( );
    To copy to clipboard, switch view to plain text mode 

    and now It works fine,

    best regards
    Tomasz
    Last edited by Tomasz; 21st July 2010 at  10:30.
  5. #4
    wysota's Avatar
    wysota 
    wysota is offline Master of Zen           
    Nokia Certified Qt Developer
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    28,434
    Thanks
    3
    Thanked 4,110 Times in 3,960 Posts
    Qt products
    Qt3  Qt4 Qt5  Qt/Embedded
    Platforms
    Unix/X11  Windows  Maemo/MeeGo
    Blog Entries
    4
    Wiki edits
    10

    Default Re: QT & SQLite - driver not loaded

    Change your code to:
    Qt Code:
              
    1. QSqlDatabase bdb = QSqlDatabase :: addDatabase ( "QSQLITE" );
    2. bdb. setDatabaseName ( "/test.db" );
    3. bdb. open ( );
    To copy to clipboard, switch view to plain text mode 
    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.

  6. The following user says thank you to wysota for this useful post:

    Tomasz (21st July 2010)
  7. #5
    sadjoker is offline Novice
    Join Date
    Feb 2008
    Posts
    50
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11  Windows

    Default Re: QT & SQLite - driver not loaded

    Hello all. As we are speaking about SQLITE driver i had a very stressful experience with that driver (4.6.2/4.6.3). I deployed over 100 copies of one program using latest sqlite driver. There was no problem anywhere... i put the dll file under the executable file in directory "sqldrivers".
    Only in some particular systems this new driver wasn`t loading... i was like O_o. I`m talking about 2% of all the systems.
    I`ve spent a lot of hours debugging remotely the machines and didn`t find a way to make it work. But i knew my old software worked on those machines before... then i switched to a sqlite dll from 4.4.0 and .. magically the driver was loaded!
    Apparently something in the driver changed but i couldn`t find time to investigate further.

    Edit: the machines were WinXP Pro SP3.
    Last edited by sadjoker; 22nd July 2010 at  18:23.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值