Problema cu legarea la baza de date
-
Am introdus codul urmator
@#include <QCoreApplication>
#include <QtSql>
#include <QtDebug>int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);// QString servername = "LOCALHOST\SQLEXPRESS";
QString servername = "LOCALHOST\MYSQL";
QString dbname = "test.dat";QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE"); db.setConnectOptions(); QString dsn = QString("DRIVER=(SQL Native Client);SERVER=%1;DATABASE=%2;UID=root;PWD=root;").arg(servername).arg(dbname);
// QString dsn = QString("DRIVER=(SQL Native Client);SERVER=%1;DATABASE=%2;Trusted_Connection=Yes;").arg(servername).arg(dbname);
// db.setDatabaseName(":memory:");
db.setDatabaseName(dsn);if(db.open()) { qDebug() << "Opened!"; db.close(); } else { qDebug() << "Error: " << db.lastError().text() ; } return a.exec();
}
@Si obtin eroarea "out of memory Error opening database"
Problema pare a fi la numele serverului sau string-ul dsn.
Mentionez ca folosesc UniServer, cu Apache si MySQL.Salutare,
MihneaEdit: Rezolvat! [ https://qt-project.org/forums/viewthread/26150/#119424 ]