PDA

View Full Version : Create a windows application with sqlite



nittalope
10th July 2009, 14:30
Hi everyone, I'm new on Qt, so maybe my problem is not that big, but I've searched a bit and didn't found a solution yet.
I've written an application using Qt under Linux environment, everything worked well. Then I've compiled it under xp and still everything worked well. Now I want to distribute it on computer that has not Qt installed, so I copied the exe compiled under xp, and with it I copied the dll needed (qtsql4, qtgui4, qtcore4, mingwm10) and when I run the application the "Unable to establish a database connection. This example needs SQLite support. Please read the Qt SQL driver documentation for information how to build it. Click Cancel to exit." message that is in a "connection.h" file that I show below. I really don't know how to go on...


#include <QTimer>
#include <QtSql>
#include <QMessageBox>

static bool createConnection()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
// db.setDatabaseName(":memory:");
db.setDatabaseName("yorkshire_db");
if (!db.open()) {
QMessageBox::critical(0, qApp->tr("Cannot open database"),
qApp->tr("Unable to establish a database connection.\n"
"This example needs SQLite support. Please read "
"the Qt SQL driver documentation for information how "
"to build it.\n\n"
"Click Cancel to exit."), QMessageBox::Cancel);
return false;
}

mcosta
10th July 2009, 15:11
to deploy an application that uses plugins you have to follow instructions in http://doc.trolltech.com/4.5/deployment.html.

you must create a "sqldrivers" subdirectory in executable directory and copy the qsqlite drivers into.

nittalope
11th July 2009, 09:35
Thank you! I am now reading it... and try to plug things in... :)

nittalope
11th July 2009, 13:25
Ok, I created the /sqldrivers directory and copied sqldrivers inside... but still the same error...
This is my application's directory tree:
\myappdirectory

- myapp.exe
- qtcore4.dll
- qtgui4.dll
- qtsql4.dll
- sqldrivers \


- qsqlite4.dll
- libqsqlite4.a

mcosta
12th July 2009, 10:11
you need to have sqlite3.dll in you path. If you don't, you can copy it in sqldrivers folder.

I suggest you to use some tool to discover dependencies. See Dependency Walker (http://www.dependencywalker.com/)

rexi
12th July 2009, 14:43
Also, you do not need libqsqlite4.a. This is a static library that would only be required at compile time if you wanted to statically link in Qt's SQLite support. But you do not need to deploy it.

nittalope
13th July 2009, 08:41
Thank you everybody...
Well, I did use dependency walker and found out I was missing msjava.dll, fixed the problem, but it wasn't my problem... :P
Still getting the message about sqlite, and dependency didn't show anything about sqlite...

I do copied sqlite3.dll in sqldrivers directory... now I am wondering if there is a version problem with the dlls...
And, by the way, I have to mention that I developed the application in linux, and compiled it in vista, and ported it to a xp enviroment... maybe there is something related to this too? :confused:
And maybe I should write a different code to found out the specific problem and not a generic

if (!db.open()) {
?!? But in this case... I don't know what to write... :(

nish
13th July 2009, 08:45
use QSqlDatabase::lastError () and QSqlError::text ()

nittalope
13th July 2009, 11:43
Well... before to start to track the error I just wanted to check if installing qt on the xp machine the app would work and... surprise! No.
So I installed the windows version of QT SDK and compiled the source files and... f**k! Same problem! Seems that sqlite drivers are not installed either...
Now I'm recompiling qt... but the question is: even without qt installed I need the application to work!

nittalope
6th August 2009, 18:52
Just to say that everything now works correct. Just needed to delete all the non .h, .cpp, .pro file (clean up the directory...) and then compile.

I compile in XP environment.

On the deployment machine I had the directory with my exe, with mingwm10.dll (taken from mingw directory in qt installation directory) and qtcore4, qtsql4, qtgui4 dlls (taken from bin directory in qt installation directory), than a directory "sqldrivers" and there the qsqlite4.dll taken from qt/plugins/sqldrivers directory in the qt installation directory.

Everytime I change something in my application I simply compile in the XP environment and then copy the exe file in the main directory.

Happy, at the end.