Quantcast
Channel: QtWebEngine
Viewing all articles
Browse latest Browse all 13965

Problem with QSqlDatabase

$
0
0
Hi, this is my very first post here and I think that it is fine to start a new thread for this problem because i have been searching for an aswer for 2 days now. I’m working with a little project where I am using sqlite database, which I created and I am not getting it to work. I have been working with databases only since this week’s monday so there is much that I don’t know yet but I am eager to learn. So here is the code and hopefully someone can point me to right direction with it: bool User::getUser() {     bool ret = false;     db_ = QSqlDatabase::addDatabase("QSQLITE","userConnection");     db_.setDatabaseName("C:/Users/Jonne/Desktop/userDatabase.db.sqlite");        // Some testing for the file     QFileInfo fi("C:/Users/Jonne/Desktop/userDatabase.db.sqlite");     if(QFile::exists("C:/Users/Jonne/Desktop/userDatabase.db.sqlite")) {          qDebug() << fi.filePath();      }       if(db_.Open()) {           qDebug() << "Database open.";           QSqlQuery query("SELECT * FROM user;",db_);         qDebug() << query.lastError();           if (query.first()) {               name_ = query.value(1).toString();             age_ = query.value(2).toInt();             gender_ = query.value(3).toString();             height_ = query.value(4).toDouble();             weight_ = query.value(5).toDouble();             ret = true;         }       }       db_.close();     return ret; } Whit this code I am getting these outputs and errors: "userConnection" QSqlError(-1, "Error opening database", "out of memory") QSqlDatabasePrivate::removeDatabase: connection 'userConnection' is still in use, all queries will cease to work. QSqlDatabasePrivate::addDatabase: duplicate connection name 'userConnection', old connection removed. "userConnection" QSqlError(-1, "Error opening database", "out of memory") QSqlDatabasePrivate::removeDatabase: connection 'userConnection' is still in use, all queries will cease to work. QSqlDatabasePrivate::addDatabase: duplicate connection name 'userConnection', old connection removed. "userConnection" QSqlError(-1, "Error opening database", "out of memory") I don’t for example understand why these errors are coming 3 times. I am getting the database from Desktop because I couldn’t get it from the project directory. Earlier I got a error message which said that there is not table named user in the database and that was when I tried to load the database from the project folder. Also I have a problem with qt-creator itself because as default it puts build and source files in the same directory and I couldn’t get it to change the build directory. Thanks in advance for any help. :)

Viewing all articles
Browse latest Browse all 13965

Trending Articles