Results 1 to 6 of 6

Thread: SQLite truble

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2006
    Location
    Some where in Argentina
    Posts
    23
    Thanks
    4
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Unhappy SQLite truble

    I've got problems with this code:

    Qt Code:
    1. QSqlQuery *cola = new QSqlQuery("SELECT id, pregunta, respuesta, referencia, dificultad, tema FROM preguntas");
    2. if( cola->exec() )
    3. {
    4. while( cola->next() )
    5. {
    6. cout<<"-----------------------------------------------"<<endl;
    7. cout<<"Numero de pregunta: "<<cola->value(0).toInt()<<endl;
    8. cout<<"Tema:" <<cola->value(5).toInt()<<endl;
    9. cout<<"Dificultad:" <<cola->value(4).toInt()<<endl;
    10. cout<<"Texto: " <<cola->value(1).toString()<<endl;
    11. cout<<"Respuesta:" <<cola->value(2).toString()<<endl;
    12. cout<<"Referencia:" <<cola->value(3).toString()<<endl;
    13. }
    14. delete(cola);
    15. return;
    16. }
    To copy to clipboard, switch view to plain text mode 

    When run it, it's stops al the first .toString() output. If the last 3 outputs are not there the cycle work fine... Any Idea????...
    Using Qt 3 with linux
    Thanks
    Last edited by jacek; 16th August 2006 at 02:16. Reason: added code tags

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: SQLite truble

    Try:
    Qt Code:
    1. cout << "Texto: " << cola->value(1).toString().ascii() << endl;
    To copy to clipboard, switch view to plain text mode 

    BTW. Why do you create QSqlQuery with new, if you delete it immediately? Won't it be simplier if you would create it on the stack?

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

    tranfuga25s (16th August 2006)

  4. #3
    Join Date
    Aug 2006
    Location
    Some where in Argentina
    Posts
    23
    Thanks
    4
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: SQLite truble

    the ascii() function didnt work...

    the pointer thats it's created and deleted it's because sqlite block the whole db in each query. I've already tryed with QSqlCursor but does't work too. Any another idea?
    what do you mean with create it on stack? using only one query in the wole object?
    Last edited by tranfuga25s; 16th August 2006 at 02:37.

  5. #4
    Join Date
    Apr 2006
    Location
    San Francisco, CA
    Posts
    186
    Thanks
    55
    Thanked 12 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: SQLite truble

    I find a lot of java programmers use new instead of the stack. Force of habit
    Software Engineer



  6. #5
    Join Date
    Aug 2006
    Posts
    26
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: SQLite truble

    Try:
    cout << "Texto: " << cola->value(1).toString().toAscii().data() << endl;

  7. #6
    Join Date
    Jul 2006
    Posts
    79
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: SQLite truble

    Quote Originally Posted by tranfuga25s
    what do you mean with create it on stack? using only one query in the wole object?
    no..
    just write
    Qt Code:
    1. QSqlQuery cola("SELECT id, pregunta, respuesta, referencia, dificultad, tema FROM preguntas");
    To copy to clipboard, switch view to plain text mode 
    and dots " . " instead of the arrows "->" when requesting a member of cola..

    then you don't need the "delete cola"..

    regards..
    aman..

Similar Threads

  1. Qt with SQLite help please
    By munna in forum Newbie
    Replies: 6
    Last Post: 11th July 2006, 14:12

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
  •  
Qt is a trademark of The Qt Company.