Results 1 to 1 of 1

Thread: QSqlRecord & QSqlQuery problem with reading values

  1. #1
    Join Date
    Sep 2015
    Posts
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QSqlRecord & QSqlQuery problem with reading values

    Hello all,

    I'm trying to read my SQLite database with Qt5 project.

    Qt Code:
    1. QString temp = "SELECT * FROM table WHERE id = 2";
    2.  
    3. qry.prepare(temp);
    4.  
    5. if(qry.exec())
    6. {
    7. QSqlRecord rec = qry.record();
    8.  
    9. for(int i=0; i<rec.count(); ++i) {
    10. qDebug()<<rec.fieldName(i); //this part works, QDebug() prints out table column names, as it should
    11. qDebug()<<rec.value(i).toString(); //this part doesn't work.. Where its "integer" field in the table I only get "0", and where its "TEXT" field in the table I only get ""
    12. }
    13. } else qDebug()<<qry.lastError().text();
    To copy to clipboard, switch view to plain text mode 

    As you can see, I'm having problems reading out values of QSqlRecord.

    Additional info>
    I'm sure my Query will only return one line, because I search by "id" field that is unique.

    Does anybody know how I should read out column field values?


    Added after 41 minutes:


    Solved it:

    QSqlQuery qry;
    QString temp = "SELECT * FROM Testiranje2 WHERE id = "+ QString::number(curr);

    qry.prepare(temp);

    if(qry.exec())
    {
    while(qry.next()) {
    int i=0;

    QSqlRecord rec = qry.record();

    for(int i=0; i<rec.count(); ++i) {
    qDebug()<<rec.fieldName(i);
    qDebug()<<qry.value(i).toString();
    }
    }
    } else qDebug()<<qry.lastError().text();
    Last edited by Rorsh; 22nd September 2015 at 23:12.

Similar Threads

  1. QSqlQuery::executedQuery () -- Bound values versus place holders
    By davethomaspilot in forum Qt Programming
    Replies: 5
    Last Post: 21st January 2014, 13:12
  2. Replies: 4
    Last Post: 22nd August 2013, 17:09
  3. Replies: 1
    Last Post: 8th August 2011, 02:21
  4. QSqlRecord problem
    By Nefastious in forum Newbie
    Replies: 1
    Last Post: 15th October 2009, 18:30
  5. QSqlRecord problem
    By stevey in forum Qt Programming
    Replies: 2
    Last Post: 24th September 2006, 23:32

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.