Quantcast
Channel: Jobs
Viewing all articles
Browse latest Browse all 18427

SQLite database stays closed.

$
0
0
I am trying to work with databases in Qt and I cant seem to find the problem in my code. string currDir = get_current_dir_name();       db = QSqlDatabase::addDatabase("QSQLITE");     db.setDatabaseName( QString::fromStdString( currDir + "\\XmatoData.sqlite" ) );       if (!db.open())     {         QMessageBox msgBox;         msgBox.setWindowTitle( "Xmato Database Error" );         msgBox.setInformativeText( "Database is not connected. Error: " + db.lastError().text()  );         msgBox.setWindowModality( Qt::ApplicationModal );         msgBox.setStandardButtons( QMessageBox::Ok );         msgBox.exec();     }     else     {         QMessageBox msgBox;         msgBox.setWindowTitle( "Xmato Success" );         msgBox.setInformativeText( "Database is connected." );         msgBox.setWindowModality( Qt::ApplicationModal );         msgBox.setStandardButtons( QMessageBox::Ok );         msgBox.exec();     } That code gives no errors… Then when I prepare a quary: if( db.isOpen() ) {     query.prepare( QString::fromStdString( _quary ) } I get a runtime error that says: QSqlQuery::prepare: database not open _quary is a valid quary. Any ideas? Thanks.

Viewing all articles
Browse latest Browse all 18427

Trending Articles