Results 1 to 3 of 3

Thread: Passing around a QSqlDatabase

  1. #1
    Join Date
    May 2006
    Posts
    70
    Thanks
    12
    Thanked 4 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Lightbulb Passing around a QSqlDatabase

    This is something I stumbled upon when compiling my Qt4 code on a windows box. I'm using Qt 4.3.1.

    Originally I had a dynamically loaded plugin (using QPluginLoader) that had a method with this syntax:
    Qt Code:
    1. QSqlDatabase database();
    To copy to clipboard, switch view to plain text mode 

    On Linux everything compiled and ran fine but when I moved my code over to the Windows box it compiled fine but gave me a: The file "c:/my/project/plugin.dll" is not a valid Qt plugin. error message.

    It took me a while to connect this message to the actual problem so I hope this helps someone else out if they are banging their heads against a wall.

    I realize that I shouldn't return a QSqlDatabase object but instead use the QSqlDatabase::addDatabase(...) and QSqlDatabase::database() static methods with a named database.

    One question I have is, is this the only Qt4 class that I shouldn't use as a return object or are there others?

  2. #2
    Join Date
    May 2006
    Posts
    70
    Thanks
    12
    Thanked 4 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Passing around a QSqlDatabase

    Ok i've delved further into this and have discovered that if I call QSqlDatabase::addDatabase from a dynamically loaded plugin the plugin will not load on windows. It loads fine under linux.

    Now I'm beginning to wonder if this is a bug or a limitation of Qt4 on windows?

    I think I'm going to have to rework things so that I'm not adding a database from a plugin.

  3. #3
    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: Passing around a QSqlDatabase

    Did you link the main application against the sql library? As far as I remember all Qt plugins are initialized in QApplication constructor, not when addDatabase is called... What does QSqlDatabase::drivers return?

Similar Threads

  1. QSqlDatabase: QMYSQL driver not loaded
    By onder in forum Newbie
    Replies: 12
    Last Post: 29th March 2017, 14:43
  2. get error number from qsqldatabase
    By mandal in forum Qt Programming
    Replies: 1
    Last Post: 19th January 2007, 10:20
  3. QCoreApplication And QSqlDatabase
    By ball in forum Qt Programming
    Replies: 1
    Last Post: 24th May 2006, 07:58
  4. Replies: 2
    Last Post: 17th May 2006, 21:01
  5. qsqldatabase does not sense db disconnect
    By rburge in forum Qt Programming
    Replies: 0
    Last Post: 9th March 2006, 18:59

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.