Results 1 to 4 of 4

Thread: QT + Sqlite not working

  1. #1
    Join Date
    Aug 2010
    Posts
    26
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Post QT + Sqlite not working

    I need to use sqlite databases with Qt, and data submiting is not working.
    I've connected a button click to this:
    Qt Code:
    1. void submit()
    2. {
    3. if(!model->database().driver()->hasFeature(QSqlDriver::Transactions))
    4. qDebug() << "sqlite driver doesn't support transactions";
    5. if(model->database().transaction())
    6. {
    7. if(model->submitAll())
    8. {
    9. model->query().finish();
    10. if(model->database().commit())
    11. {
    12. model->query().exec();
    13. commitBtn->setEnabled(false);
    14. return;
    15. }
    16. }
    17. }
    18. model->database().rollback();
    19. QMessageBox::information(
    20. this,
    21. tr("Database error"),
    22. model->database().lastError().text());
    23. }
    To copy to clipboard, switch view to plain text mode 
    I've once tried without the query stop stuff but no success, two days since i've started searching around a way but nothing. I hope you guys can help me, thanks in advance, and sorry my bad english.
    Last edited by BrainStorm; 10th August 2010 at 20:52.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QT + Sqlite not working

    Have you tried it without the transaction? Because I think submitAll() also uses transactions and they may interfere. Just a wild guess...

    And you call always
    Qt Code:
    1. model->database().rollback();
    To copy to clipboard, switch view to plain text mode 
    ! That is also not the best solution.

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

    BrainStorm (14th August 2010)

  4. #3
    Join Date
    Aug 2010
    Posts
    26
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QT + Sqlite not working

    Quote Originally Posted by Lykurg View Post
    Have you tried it without the transaction? Because I think submitAll() also uses transactions and they may interfere. Just a wild guess...

    And you call always
    Qt Code:
    1. model->database().rollback();
    To copy to clipboard, switch view to plain text mode 
    ! That is also not the best solution.
    I've tried:
    Qt Code:
    1. void submit()
    2. {
    3. if(model->submitAll())
    4. {
    5. //model->database().transaction();
    6. if(model->database().commit())
    7. {
    8. commitBtn->setEnabled(false);
    9. }
    10. else
    11. QMessageBox::information(
    12. this,
    13. tr("Database error"),
    14. model->database().lastError().text());
    15. }
    16. else
    17. QMessageBox::information(
    18. this,
    19. tr("Database error"),
    20. model->database().lastError().text());
    21. }
    To copy to clipboard, switch view to plain text mode 

    and the 'commit' returns false, showing the following error:
    cannot commit - no transaction is active, unable to commit transaction.
    Uncommenting that line works ok, 'commit' returns true, but no database change, nothing happens..

    Last edited by BrainStorm; 10th August 2010 at 23:45.

  5. #4
    Join Date
    Aug 2010
    Posts
    26
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QT + Sqlite not working

    I solved the problem!
    I was doing "model->removeCollumn(0)" to hide id's collumn, and this was crashing the submitAll(), the right way to hide a collumn is to do "view->hideCollumn(0)"
    thanks Lykurg's for trying to figure it out with me.
    Last edited by BrainStorm; 11th August 2010 at 01:56. Reason: spelling corrections

Similar Threads

  1. [Qt][SQLite] Two problems with SQLite.
    By Xandareva in forum Newbie
    Replies: 6
    Last Post: 6th April 2010, 23:06
  2. OUT OF MEMORY - Error while working with sqlite
    By Askar in forum Qt Programming
    Replies: 1
    Last Post: 27th November 2009, 23:54
  3. SQLite with Qt4
    By MIH1406 in forum Newbie
    Replies: 6
    Last Post: 15th September 2009, 04:47
  4. SQLite in QT
    By sophister in forum Qt Programming
    Replies: 11
    Last Post: 8th April 2009, 16:09
  5. working with SQLite
    By bhs-ittech in forum Qt Programming
    Replies: 3
    Last Post: 15th September 2008, 07:51

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.