Results 1 to 20 of 22

Thread: SQLite make problems

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: SQLite make problems

    Could you show us your code used to manipulate the database?

  2. #2
    Join Date
    Jan 2006
    Posts
    273
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: SQLite make problems

    Of course:

    Have you a idea?
    Qt Code:
    1. // Connect to the SQLITE Database
    2. bool MainWindow::connectToDB()
    3. {
    4. //Um PostgreSQL zu vervenden muss der QPSQL Treiber QPSQL verwendet werden.
    5. QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    6. db.setDatabaseName("LernIT.db");
    7. }
    8.  
    9. // QSQLTableModel to show and manipulate data on the sqlite database
    10. void MainWindow::showWords()
    11. {
    12. ui.description_le->setDisabled(true);
    13. setWhite();
    14. ui.l1_le->clear();
    15. ui.l2_le->clear();
    16. ui.plural_le->clear();
    17. ui.description_le->clear();
    18.  
    19. model->setTable("words_tbl");
    20. model->setEditStrategy(QSqlTableModel::OnFieldChange);
    21. model->select();
    22. //model->removeColumn(0); // don't show the ID
    23. model->setHeaderData(1, Qt::Horizontal, tr("Deutsch"));
    24. model->setHeaderData(2, Qt::Horizontal, tr("Portuguiesisch"));
    25.  
    26. ui.tableView->setModel(model);
    27. ui.tableView->setColumnHidden(0, true);
    28. ui.tableView->sortByColumn(1);
    29. ui.tableView->show();
    30. }
    31.  
    32.  
    33. // I am using this Script to insert new rows to the database:
    34. QSqlQuery insert;
    35. insert.prepare("insert into words_tbl (language1, language2, plural, description) values ('"
    36. + ui.l1_le->text() + "', '" + ui.l2_le->text() + "','" + ui.plural_le->text() + "', '" + ui.description_le->text() + "')");
    37. if( ! insert.exec() ) {
    38. QMessageBox::information(this,"LernIT",insert.lastError().text());
    39. return;}
    40.  
    41. //To select some data i am using this script:
    42. QString random;
    43. QSqlQuery count("SELECT words_id FROM words_tbl WHERE rowid>=random() % (SELECT max(words_id)+1 FROM words_tbl) LIMIT 1;");
    44.  
    45. while(count.next())
    46. {
    47. random = count.value(0).toString();
    48. }
    To copy to clipboard, switch view to plain text mode 
    Attached Files Attached Files
    Last edited by jacek; 6th June 2007 at 22:09. Reason: wrapped too long line
    Think DigitalGasoline

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: SQLite make problems

    What's the point of using "prepare" here if you don't make any bindings afterwards?

Similar Threads

  1. QMake make install problems
    By cookiem in forum Qt Programming
    Replies: 12
    Last Post: 4th December 2008, 15:34
  2. SQLITE database problems
    By phoenix in forum Newbie
    Replies: 3
    Last Post: 30th April 2007, 21:38
  3. Window OS make distclean && qmake && make one line
    By patrik08 in forum General Programming
    Replies: 4
    Last Post: 22nd March 2007, 10:43
  4. Compiling with Qmake/Make
    By VireX in forum Newbie
    Replies: 25
    Last Post: 22nd February 2007, 05:57
  5. Qt4.1.4 make errors.
    By impeteperry in forum Installation and Deployment
    Replies: 11
    Last Post: 1st July 2006, 17:27

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.