Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Sqlite query returns no data?
Forum Updated to NodeBB v4.3 + New Features

Sqlite query returns no data?

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 1.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hunk
    wrote on last edited by
    #1

    qDebug result is 0

    db = QSqlDatabase::addDatabase("QSQLITE", "conn");
    db.setDatabaseName("qt_sqlite_test.db");
    if(!db.open())
    {
        QMessageBox::critical(NULL, QObject::tr("Collection"), QObject::tr("Connection Failed"));
    }
    QSqlQueryModel *model = new QSqlQueryModel;
    model->setQuery("SELECT * FROM apply",db);
    qDebug()<<(model->rowCount());
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Please enclose your code with coding tags.

      Check the errors returned by your model to see what might go wrong.

      Also ensure that that the file you want to open is accessible, otherwise a new empty database will be created. Since you are testing, use a complete path to your database in setDatabaseName

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • H Offline
        H Offline
        hunk
        wrote on last edited by
        #3

        sqlite file in the root directory of the current project.

        Use a full path, the error remains.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Did you check the errors ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • Q Offline
            Q Offline
            qxoz
            wrote on last edited by
            #5

            What says last error?:
            @qDebug()<<(model->lastError());@

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved