Hi , i want to use an existing database from my project , but i don't know how.
I used QSqlDatabase, but no good result.
How to do it ??
Hi , i want to use an existing database from my project , but i don't know how.
I used QSqlDatabase, but no good result.
How to do it ??
Show the code you have.
Nobody can help you fix a problem if nobody can look what the problem might be.
Cheers,
_
you can connect to database with following code:
#include "mainwindow.h"
#include <QApplication>
#include <QtSql>
#include <QMessageBox>
bool createConnection()
{
QSqlDatabase db = QSqlDatabase::addDatabase("my driver QPSQL");
db.setHostName("");
db.setDatabaseName("my testdb");
db.setUserName("");
db.setPassword("");
if (!db.open()) {
QMessageBox::warning(0, QObject::tr("Database Error"),
db.lastError().text());
return false;
}
return true;
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
if (!createConnection())
return 1;
MainWindow form;
form.resize(500, 600);
form.show();
return app.exec();
}
Bookmarks