Results 1 to 7 of 7

Thread: SQLite doesnt return data

  1. #1
    Join Date
    Mar 2010
    Location
    Brazil
    Posts
    39
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default SQLite doesnt return data

    I'm using Qt + Sqlite3 at Kubuntu 11.04.

    When i execute the program from QtCreator or Shell, it runs ok.
    The problem is when i try execute it (compiled) by double-click. It can not receive the data from database file. Its connect with the database file but doesnt return the data.

    I'm using this to connect:
    db = QSqlDatabase::addDatabase("QSQLITE");
    db.setDatabaseName("dataBase.db");
    db.open();

    This works fine.

    But when i run this, its return nothing:
    QSqlQuery resultado = db.exec("select * from pessoas");
    while (resultado.next())
    ui->plainTextEdit->appendPlainText(resultado.value(0).toString() +
    " - " + resultado.value(1).toString());

    Any idea about what is happening?

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,677
    Thanks
    13
    Thanked 1,596 Times in 1,524 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: SQLite doesnt return data

    No, but I'm sure if you look at the return value from QSqlDataBase::open() and the state of the QSqlQuery returned from QSqlDatabase::exec() you would be given a clue. You should be looking at QSqlQuery::isActive(), QSqlDatabase::lastError() and/or QSqlQuery::lastError().

    As the docs say,
    QSqlDatabase::exec() is deprecated. Use QSqlQuery::exec() instead.
    You also wanted [code][/code] tags rather than [qtclass]

  3. #3
    Join Date
    Apr 2011
    Posts
    124
    Thanks
    1
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows Symbian S60

    Default Re: SQLite doesnt return data

    Probably the database record is blank. Probably because you're executing in a different environment and the database is not where it ought to be.

    Display QFileInfo("dataBase.db").absoluteFilePath() to see where the app is looking for the database.

  4. #4
    Join Date
    Mar 2010
    Location
    Brazil
    Posts
    39
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: SQLite doesnt return data

    Quote Originally Posted by DanH View Post
    Probably the database record is blank. Probably because you're executing in a different environment and the database is not where it ought to be.

    Display QFileInfo("dataBase.db").absoluteFilePath() to see where the app is looking for the database.
    The app is looking for the db, everything is ok about this. When a run the app at QtCreator, i can to get the records.
    The QSqlDataBase:pen() return true, the connection is working...

  5. #5
    Join Date
    Apr 2011
    Posts
    124
    Thanks
    1
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows Symbian S60

    Default Re: SQLite doesnt return data

    You said when you "execute it (compiled) by double-click" you have problems. When you do that, you're very likely getting a different default directory, so the DB is not where the program's looking for it.

    Do as I said and display the path where the code is looking for the DB.

  6. #6
    Join Date
    Mar 2010
    Location
    Brazil
    Posts
    39
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: SQLite doesnt return data

    I got solve the problem he was having.
    Strangely, even notifying that it was connected to my application could not find the path to the SQLite file that was in the same folder as the application executable.
    To resolve this I used the following code:

    Qt Code:
    1. db.setDatabaseName(QApplication::applicationDirPath() +
    2. QDir::separator() + "dataBase.db");
    To copy to clipboard, switch view to plain text mode 

  7. #7
    Join Date
    Apr 2011
    Posts
    124
    Thanks
    1
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows Symbian S60

    Default Re: SQLite doesnt return data

    Like I said, you were looking in the wrong place.

Similar Threads

  1. Replies: 2
    Last Post: 27th June 2009, 20:26
  2. Sqlite and UTF8 data
    By kroenecker in forum Qt Programming
    Replies: 2
    Last Post: 19th April 2009, 15:49
  3. Problem in printing the data return /read from QTcpsocket
    By skumar434 in forum Qt Programming
    Replies: 3
    Last Post: 20th February 2009, 20:36
  4. How to return a lot of data from a QDialog
    By Morea in forum Qt Programming
    Replies: 2
    Last Post: 20th October 2008, 13:10
  5. data not being retained in sqlite DB
    By sticcino in forum Qt Programming
    Replies: 2
    Last Post: 2nd July 2008, 11:42

Tags for this Thread

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.