PDA

View Full Version : building an app with QSqlDatabase::drivers()



mgrzyma
6th February 2007, 05:51
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 (?)

jacek
6th February 2007, 11:26
Where did you copy that driver to? It should be in "sqldrivers" subdirectory in the directory where your executable is.

mgrzyma
7th February 2007, 02:58
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?

wysota
7th February 2007, 11:27
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.

mgrzyma
20th February 2007, 02:47
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?

jacek
20th February 2007, 21:19
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 (http://www.dependencywalker.com) whether that plugin doesn't require some additional libraries.



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.