PDA

View Full Version : SQLite



igoreshka3333
15th June 2015, 22:34
Hi! I have made a project which was connected with database. Database was connected succesfully:



m_mydb = QSqlDatabase::addDatabase( "QSQLITE" );
m_mydb.setDatabaseName( "D:/Programming/Programming_soft/SQLite/DB/EmployeeInfo.db" );

if( !m_mydb.open() )
ui->label->setText( "Failed to open the database" );
else
ui->label->setText( "Connected..." );

But I can't to make a query. I used method QSqlQuery::exec() and he returns false, when it must to return true!



QSqlQuery qry;

qWarning() << qry.exec( "SELECT name FROM employee" );

I tried to make the same query in SQLiteManager without any problems... What can you promt to me?

Added after 9 minutes:

Sorry, guys! It was miserable mistake, problem was in extension of file. It was .sqlite, but I wrote .db and was created a file without any data))

jefftee
15th June 2015, 23:03
You should also change your QSqlQuery qry variable allocation to QSqlQuery qry(m_mydb) to ensure you always use the connection your QSqlDatabase is using.

igoreshka3333
16th June 2015, 06:59
OK, thank u)