Im trying to connect to a mysql server with this code:
#include "testemysql1.h"
#include <QSqlDatabase>
#include <QtSql>
#include <QMessageBox>
testeMYSQL1
::testeMYSQL1(QWidget *parent, Qt
::WFlags flags
){
ui.setupUi(this);
}
testeMYSQL1::~testeMYSQL1()
{
}
void testeMYSQL1::on_pushButton_clicked()
{
db.setHostName("servidor");
db.setDatabaseName("teste");
db.setUserName("root");
db.setPassword("");
if (!db.open())
QMessageBox::critical(0, tr
("Error"),
QString("The error:\n%1").
arg(db.
lastError().
text()));
// bool ok = db.open();
//lineEdit
}
#include "testemysql1.h"
#include <QSqlDatabase>
#include <QtSql>
#include <QMessageBox>
testeMYSQL1::testeMYSQL1(QWidget *parent, Qt::WFlags flags)
: QMainWindow(parent, flags)
{
ui.setupUi(this);
}
testeMYSQL1::~testeMYSQL1()
{
}
void testeMYSQL1::on_pushButton_clicked()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("servidor");
db.setDatabaseName("teste");
db.setUserName("root");
db.setPassword("");
if (!db.open())
QMessageBox::critical(0, tr("Error"), QString("The error:\n%1").arg(db.lastError().text()));
// bool ok = db.open();
//lineEdit
}
To copy to clipboard, switch view to plain text mode
But I got this error:
QSqlDatabase: available drivers
: QSQLITE QODBC3 QODBC QPSQL7 QPSQL
QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QODBC3 QODBC QPSQL7 QPSQL
To copy to clipboard, switch view to plain text mode
Im using QT4.4 Commercial and Visual Studio 2005.
Thanks in advance
Renan
Bookmarks