Results 1 to 6 of 6

Thread: building an app with QSqlDatabase::drivers()

  1. #1
    Join Date
    Jan 2007
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default building an app with QSqlDatabase::drivers()

    4.2.2 on XP with mingw32:
    this section of code works fine if I run the .exe on the machine where it was compiled:
    QSqlConnectionDialog::QSqlConnectionDialog(QWidget *parent)
    : QDialog(parent)
    {
    ui.setupUi(this);
    QStringList drivers = QSqlDatabase::drivers();
    ui.comboDriver->addItems(drivers);
    }
    however, I would like to use my program on other machines and after copying the .exe (and all the dll's that it asks for: QtGuid4.dll, QtCored4.dll, QtSqld4.dll) to a different PC the line:
    QStringList drivers = QSqlDatabase::drivers();
    returns an empty QStringList.
    In other words: 'QSqlDatabase::drivers().isEmpty()' is true.

    I know it's probably a stupid question but if I just need the "QODBC" driver what do i need to do to either:
    1 - incorporate the QODBC driver with the .exe, or
    2 - find the correct .dll (where is this driver anyway? I tried the one from 'C:\Qt\4.2.2\plugins\sqldrivers' unsuccessfully) to copy it along with the rest, or
    3 - make my own (?)

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: building an app with QSqlDatabase::drivers()

    Where did you copy that driver to? It should be in "sqldrivers" subdirectory in the directory where your executable is.

  3. #3
    Join Date
    Jan 2007
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: building an app with QSqlDatabase::drivers()

    Ahaaa! That worked. Thanks a lot Jacek.
    Now, if i don't want to create any subdirectories on the client machine, is there a way to somehow 'embed' the sql driver within the executable?
    also:
    i bet you there is a secret way to configure another thing that i tried to 'fix' by tinkering with the makefiles: why in the 4.1.1. version the executables compiled into the 'release' directory (and their size was minimal, which was great) but now in 4.2.2 they end up in 'debug' and their size is huge?

  4. #4
    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: building an app with QSqlDatabase::drivers()

    Now, if i don't want to create any subdirectories on the client machine, is there a way to somehow 'embed' the sql driver within the executable?
    Yes, recompile Qt with -qt-sql-drivername instead of -plugin-sql-drivername or compile your application statically and use a static version of the driver (this includes recompiling Qt as well).

    i bet you there is a secret way to configure another thing that i tried to 'fix' by tinkering with the makefiles: why in the 4.1.1. version the executables compiled into the 'release' directory (and their size was minimal, which was great) but now in 4.2.2 they end up in 'debug' and their size is huge?
    The "secret way" is to add CONFIG+=release to your project file and remove a possible occurence of the "debug" option from the CONFIG variable. Remember to rerun qmake afterwards.

  5. #5
    Join Date
    Jan 2007
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: building an app with QSqlDatabase::drivers()

    thanks,
    i added: CONFIG += release to .pro and i got the release version running on the machine where my qt is installed, but now again, after copying the release .exe and (what i think are) all needed dll's to a different PC i am back to the original problem with:
    QStringList drivers = QSqlDatabase::drivers() returning an empty QStringList; ('QSqlDatabase::drivers().isEmpty()' is true)
    this time i am sure my driver is in the "sqldrivers" subdirectory (in the directory where the release executable is), debug version still runs just fine;
    i did not recompile Qt with -qt-sql-drivername instead of -plugin-sql-drivername yet, should i?

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: building an app with QSqlDatabase::drivers()

    Quote Originally Posted by mgrzyma View Post
    this time i am sure my driver is in the "sqldrivers" subdirectory (in the directory where the release executable is)
    Is that a release version of the plugin? Check with Dependency Walker whether that plugin doesn't require some additional libraries.

    Quote Originally Posted by mgrzyma View Post
    i did not recompile Qt with -qt-sql-drivername instead of -plugin-sql-drivername yet, should i?
    It isn't necessary, but it will definitely solve the problem.

Similar Threads

  1. Replies: 17
    Last Post: 11th July 2010, 23:41
  2. Building plugins for dummies
    By Jeff_Birt in forum Qt Programming
    Replies: 3
    Last Post: 24th January 2007, 03:21
  3. Building a third party library
    By munna in forum General Programming
    Replies: 1
    Last Post: 6th October 2006, 20:43
  4. Basic: problem building designer application
    By kingslee in forum Qt Tools
    Replies: 2
    Last Post: 31st August 2006, 15:26
  5. Problem building Qt4.1.0 with thread support on windows XP
    By pavithra in forum Installation and Deployment
    Replies: 1
    Last Post: 1st April 2006, 11:35

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.