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".
Probably the point is dbpath,try with