Results 1 to 3 of 3

Thread: Impossible to get data from QSqlQuery object[Solved]

  1. #1
    Join Date
    Apr 2009
    Location
    Valencia (Spain)
    Posts
    245
    Thanks
    38
    Thanked 19 Times in 19 Posts
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Impossible to get data from QSqlQuery object[Solved]

    Hi,

    I have the next code:

    Qt Code:
    1. QSqlQuery data(QString("SELECT sname, ssurname FROM games WHERE id =3")
    2. ,(the database, it works so the problem is not here));
    3.  
    4. QVariant QVtemp;
    5. for(int i = 0; i < 2; ++i)
    6. {
    7. QVtemp = data.value(i);
    8. QString test1= data.value(i).toString();
    9. }
    To copy to clipboard, switch view to plain text mode 

    "test1" is always "". The query works fine, because data.size is 1, so I think the problem should be somewhere else... any idea?

    thanks!
    Last edited by jano_alex_es; 27th April 2009 at 15:15.

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Impossible to get data from QSqlQuery object

    use QSqlQuery::next/previous/first/last/seek for navigation between records.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. The following user says thank you to spirit for this useful post:

    jano_alex_es (27th April 2009)

  4. #3
    Join Date
    Apr 2009
    Location
    Valencia (Spain)
    Posts
    245
    Thanks
    38
    Thanked 19 Times in 19 Posts
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Re: Impossible to get data from QSqlQuery object

    in the end my problem was that I didn't set up the record.

    Something easy to find, thanks to you, with "data.First()" (and, after that, access with data.value(index))

    thanks!

Similar Threads

  1. Replies: 4
    Last Post: 19th February 2009, 11:10
  2. Best way to display lots of data fast
    By New2QT in forum Newbie
    Replies: 4
    Last Post: 16th October 2008, 22:46
  3. Replies: 7
    Last Post: 29th August 2008, 10:24
  4. speed of setdata - lots of items in treeview
    By Big Duck in forum Qt Programming
    Replies: 4
    Last Post: 6th July 2006, 12:53
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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.