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 database with Qt
Forum Updated to NodeBB v4.3 + New Features

SQLite database with Qt

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 3.1k 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.
  • T Offline
    T Offline
    tita90
    wrote on last edited by
    #1

    Hello,
    I have a problem with a Sqlite database in my Qt project: I created a file "database.db" with the application SQLite database Browser inside the root directory of my project but I can't operate on it succesfully. My code is this:

    @
    bool Database::InizDb(QString x="database.db"){
    QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    db.setDatabaseName(x);
    if (db.open()){
    cout <<"true";
    //return true;
    }
    else {
    cout << "false";
    //return false;
    }
    QSqlQuery query;
    query.exec("SELECT cognome FROM Profilo");
    cout << query.size();
    //...
    }
    @

    the printed is "true" and "-1". The problem is that it prints "true" also if i write a wrong database name, then the "-1" means that the query is wrong but it isn't!

    What can it be? Who can help me?

    Thank you very much

    [EDIT: code formatting, pleas wrap in @-tags, Volker]

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

      To cite "QSqlQuery::size() ":http://doc.qt.nokia.com/4.7/qsqlquery.html#size:

      bq. Returns the size of the result (number of rows returned), or -1 if the size cannot be determined or if the database does not support reporting information about query sizes. [Emphasis by me]

      SQLite does not support reporting the number of rows in the result set.

      http://www.catb.org/~esr/faqs/smart-questions.html

      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