Hey all
I have a problem with mysql connection. When i try to connect to a mysql database i get the error "driver not loaded".
I use the following code:
#include <QApplication>
#include <QLabel>
#include <QSqlDatabase>
#include <QSqlError>
#include <QMessageBox>
bool createConnection()
{
db.setHostName("***********");
db.setPort(3306);
db.setDatabaseName("wachtrij");
db.setUserName("root");
db.setPassword("");
if (!db.open()) {
db.lastError().text());
return false;
}
return true;
}
int main(int argc, char *argv[])
{
if(createConnection() != false)
{
label->setText("Database connected");
}
else
{
label->setText("Database failed to connect");
}
label->show();
return app.exec();
}
#include <QApplication>
#include <QLabel>
#include <QSqlDatabase>
#include <QSqlError>
#include <QMessageBox>
bool createConnection()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("***********");
db.setPort(3306);
db.setDatabaseName("wachtrij");
db.setUserName("root");
db.setPassword("");
if (!db.open()) {
QMessageBox::critical(0, QObject::tr("Database Error"),
db.lastError().text());
return false;
}
return true;
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QLabel *label = new QLabel;
if(createConnection() != false)
{
label->setText("Database connected");
}
else
{
label->setText("Database failed to connect");
}
label->show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
I had a problem with compiling the code but that is solved.
I followed these instructions: http://wiki.qtcentre.org/index.php?t...ws_using_MinGW
and when i want to compile i ad QT += sql to the .pro file
I've searched trough this forum and other forums but couldn't find the solution.
I am using Qt 4.3 and mingw on windows xp
I hope you can help me.
Bookmarks