QSqlDatabase not opening

2.3k views Asked by At

I am unable to understand what I am doing wrong here. I am using Qt 5.7.1 and the code is as follows:

    QString filePath = QCoreApplication::applicationDirPath();
    QString dbPath = QDir(filePath).absoluteFilePath("../../../Database");

    m_db = QSqlDatabase::addDatabase("QSQLITE", "user_connection");
    m_db.setDatabaseName(dbPath + "/Sensor_Objects.db");

    qDebug() << filePath << " & " << dbPath;

    if (!m_db.open())
       qDebug() << "Database Error: " + m_db.lastError().text();
    else
    {
       qDebug() << "Database: connection ok";
        createDatabase("Sensor_Objects");
        m_db.close();
    }

qDebug() is printing the paths to the directories correctly and yet m_db.open() fails with the error "Database Error: out of memory Error opening database".

1

There are 1 answers

0
Antonio Del Sannio On

Probably the point is dbpath,try with

m_db.setDatabaseName(dbPath.toLatin1() + "/Sensor_Objects.db");