PDA

View Full Version : QtService & QtSql



acedanans
24th November 2010, 12:17
Hi all~ I've make a small service by qtservice, the service will query database by QSqlDatabse with MySql plugin.

on my developement platform, all thing work fine.
on a clean system which we will distributed our app to, the service itself work fine, but the QSqlDatabase object will be invalid while call "addDatabase", which usually means DB driver not found. i've already copy all qt dll and plugins to the same path with execute file, I also try to put them in system32, still not working~

it only happen if QSqlDatabase object is used in a qtservice application. it is working correctly while used in a general application.

so my problem is: how qtservice manage its plugin path? how to install plugin path correctly while we distribute developed qtservice application?

any answer would be appreciate~~
thx~~~

Lesiok
25th November 2010, 07:41
I think the problem is missing MySQL DLL's. Use DependencyWalker on this "clean" machine and You will see what is missing.

P.S.
I see that in "normal" mode all is working :(

acedanans
25th November 2010, 10:36
really thx for reply~

I understand the scenario is qtsql did not find qsqlmysql4.dll plugin.

my confussion is: Why? i've already put this plugin in the same path as execution file. and also in "C:\QT\4.6.2-vc\qt\plugins\sqldrivers" which is same as my developement pc.

Why the plugin would be found if the execution file using qtsql is build as a normal application but not a "qtservice " application?

P.S. the service application is launch by qtservicecontroller or system service control panel (after service installed) but NOT directly execute.

RazZziel
29th November 2011, 14:29
One year later, was any solution found for this problem?

I'm facing the same issue with QtService and QMYSQL. My service only reports to have found these plugins: "QSQLITE, QODBC3, QODBC'", but I need QMYSQL, which is right in my sqlplugins directory.

bu7ch3r
29th November 2011, 14:42
I have the same problem but on the static version of Qt. If you have the default version of QT you must compile MYSQL driver using the libraryes provided by the mysql site. When you deploy the app you must make another directory where the exe is, named "sqldrivers" and copy qslmysql.dll there.


Here is a link that helped me to build it for the dynamic version of qt.
http://doc.qt.nokia.com/stable/sql-driver.html

RazZziel
29th November 2011, 14:47
That's not exactly the problem here: our programs work flawlessly when executed as standalone applications. I use the default version of Qt, I've compiled the MySQL driver as that website says, and everything runs fine on a regular Qt4 application.

The problem is trying to run a QtService with the MySQL plugin, as the service won't find the plugin. A possible solution would be to recompile Qt4 with -qt-sql-driver, but that'd be really time consuming and I was looking for a quicker solution.

bu7ch3r
29th November 2011, 14:54
Do you deploy the service in Windows or in unix ?
If you manage to compile using -qt-sql-mysql please tell me how:) It seems that I cannot manage to compile using nmake...

RazZziel
29th November 2011, 14:58
I'm working on Windows right now, but with mingw, not with msvc. I once managed to compile with -qt-sql-mysql, but I was cross-compiling on Linux for QtEmbedded.

RazZziel
29th November 2011, 20:38
Hm, actually, it works like a charm in release, it only fails on debug, so there must be something fishy with my debug libraries...

bu7ch3r
30th November 2011, 07:28
Probably you already know that on debug it searches for qsqlmysql4.dll with d in the name: qsqlmysqld4.dll or something.

RazZziel
30th November 2011, 08:15
Indeed, but for some reason it won't find my sqldrivers/qsqlmysqld4.dll, go figure...

AmiArt
3rd October 2014, 12:30
Try this, it works for me.


int main(int argc, char *argv[])
{
QString app_path = QFileInfo(QString::fromLocal8Bit(argv[0])).absolutePath();
QCoreApplication::addLibraryPath(app_path);

OpcService service(argc, argv);
return service.exec();
}


And copy qsqlmysql4.dll to "sqldrivers" subdirectory of your .exe file.