Results 1 to 3 of 3

Thread: SQLite

  1. #1
    Join Date
    Nov 2014
    Posts
    12
    Qt products
    Qt5

    Default Re: SQLite

    Hi! I have made a project which was connected with database. Database was connected succesfully:

    Qt Code:
    1. m_mydb = QSqlDatabase::addDatabase( "QSQLITE" );
    2. m_mydb.setDatabaseName( "D:/Programming/Programming_soft/SQLite/DB/EmployeeInfo.db" );
    3.  
    4. if( !m_mydb.open() )
    5. ui->label->setText( "Failed to open the database" );
    6. else
    7. ui->label->setText( "Connected..." );
    To copy to clipboard, switch view to plain text mode 

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

    Qt Code:
    1.  
    2. qWarning() << qry.exec( "SELECT name FROM employee" );
    To copy to clipboard, switch view to plain text mode 

    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))
    Last edited by igoreshka3333; 15th June 2015 at 22:34.

  2. #2
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: SQLite

    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.
    Last edited by jefftee; 15th June 2015 at 23:19.

  3. #3
    Join Date
    Nov 2014
    Posts
    12
    Qt products
    Qt5

    Default Re: SQLite

    OK, thank u)

Similar Threads

  1. Sqlite
    By malavika in forum Newbie
    Replies: 2
    Last Post: 24th October 2011, 10:22
  2. Using Qt with SQLite
    By lxman in forum Qt Programming
    Replies: 3
    Last Post: 3rd July 2011, 19:52
  3. [Qt][SQLite] Two problems with SQLite.
    By Xandareva in forum Newbie
    Replies: 6
    Last Post: 6th April 2010, 23:06
  4. xml + sqlite
    By eleanor in forum Qt Programming
    Replies: 1
    Last Post: 7th May 2009, 17:06
  5. SQLite in QT
    By sophister in forum Qt Programming
    Replies: 11
    Last Post: 8th April 2009, 16:09

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.