View Full Version : SqlDriverPlugin
Hello folks,
I've installed the mysql driver plugin on winXP after this guide:
http://wiki.qtcentre.org/index.php?title=Building_the_QMYSQL_plugin_on_Wind ows_using_MinGW
After this installation I've cleaned the plug-in cache. But it dosn't work. I have allways the error, driver not loaded.
Here is the code for the mysql connection:
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName(hostnameLineEdit->text());
db.setUserName(usernameLineEdit->text());
db.setPassword(passwordLineEdit->text());
db.setDatabaseName(dbnameLineEdit->text());
if (!db.open())
QMessageBox::critical(0, tr("Error"), QString("The error:\n%1").arg(db.lastError().text()));
Under linux all works fine. Whats the problem with windows?
so long
jd
Have you tried opening the compiled plugin in Dependency Walker (http://www.dependencywalker.com/)?
Yes, I can't see any problems.
I've wrote a small application with database support:
test.h
#ifndef TEST_H_
#define TEST_H_
#include <QPushButton>
class MyClass : public QObject
{
Q_OBJECT
public:
MyClass();
QPushButton *myButton;
public slots:
void mySlot();
};
#endif /*TEST_H_*/
test.cpp
#include <QtGui>
#include "test.h"
#include <QtSql>
MyClass::MyClass()
{
myButton = new QPushButton;
connect(myButton, SIGNAL(clicked()),
this, SLOT(mySlot()));
myButton->setText(tr("Klick mich!"));
myButton->show();
}
void MyClass::mySlot()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("192.168.2.229");
db.setUserName("qfinancialoffice");
db.setPassword("test");
db.setDatabaseName("qfinancialoffice");
if (!db.open())
QMessageBox::critical(0, tr("Error"), QString("The error:\n%1").arg(db.lastError().text()));
else
QMessageBox::critical(0, tr("OK"), QString("OK"));
}
This works fine! (Win & Linux)
In my other and bigger application I get the error driver not loaded. I can't locate the problem, but under Linux all works fine. The code for the database connection is the same there is no wrapper class or anything else. Why exits the problem under windows only. How can I locate the problem? I have not enough experience with windows to do this.
Are you experiencing the problem on the development machine or while deploying? Do you have multiple Qt installations in Windows?
No, only 4.3.4.
I've no idea to locate the problem. I think there is a big mistake in my code. Now, I'll debug the code to locate the problem. For Example:
main.cpp
#include <QApplication>
#include "MainWindow/MainWindow.h"
#include "LoginDialog/LoginDialog.h"
#include "Settings/Settings.h"
#include "StartupWizard/StartupWizard.h"
#include <QtSql>
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
QCoreApplication::setOrganizationName("NORO-Automaten");
QCoreApplication::setOrganizationDomain("http://www.noro.de");
QCoreApplication::setApplicationName("QFinancialOffice");
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("192.168.2.229");
db.setUserName("qfinancialoffice");
db.setPassword("test");
db.setDatabaseName("qfinancialoffice");
if (!db.open())
QMessageBox::critical(0, QString("Error"), QString("The error:\n%1").arg(db.lastError().text()));
else
QMessageBox::critical(0, QString("OK"), QString("OK"));
CSettings *configure = new CSettings;
if (configure->settings.firstrun) {
QMessageBox::information(0, QObject::tr("Erster Start"), QObject::tr("Dies ist der erste Start von <b>QFinancialOffice</b>.\nAls erstes muessen Sie <b>QFinancialOffice</b> konfigurieren."));
ClassWizard *wizard = new ClassWizard;
if (wizard->exec() == ClassWizard::Accepted) {
QMessageBox::information(0, QObject::tr("Neustart"), QObject::tr("QFinancialOffice wird jetzt neu gestartet."));
QProcess process;
process.startDetached(QApplication::applicationFil ePath());
process.waitForStarted();
}
delete configure;
return 1;
} else {
CLoginDialog *login = new CLoginDialog;
if (login->exec() == CLoginDialog::Accepted) {
CMainWindow *window = new CMainWindow;
window->show();
} else {
QMessageBox::critical(0, QString("Fehler"), QString("Der Login war nicht erfolgreich\n Programm kann nicht gestartet werden.\n"));
return 1;
}
}
app.exec();
}
You can see, at first I'll test my local database connection, this test fails on windows but not on linux. In my test program there is the same test code and it works.
I don't know, but can it be, that I have an memory problem?
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
This object will be saved on the stack. If my stack is full I had an undefined problem or not?
The problem is unbelievabl.
Ok, now I've sloved the problem. I've upgraded my Qt version to 4.4.0 and all works fine. Thanks for help.
so long
jd
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.