Results 1 to 3 of 3

Thread: QSqlite problem

  1. #1
    Join Date
    Jan 2006
    Posts
    115
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QSqlite problem

    Hello anyone,

    I using Qt-4.2.3 on Windows XP
    I have made a database called freesdb and insert the records through a dialog and works fine.
    The problem is i can insert into the database up to 256 records and then in the same direktory where the freesdb is staying a another database pops up called freesdb-journal.
    These freesdb-journal is blockking further inserting records in my freesdb.
    I read over the net there no limitation of records in Sqlite database.

    How is possible to get more records in my freesdb. ( more then 256 records).

    Here my code for the connection for my database.
    connection.h
    Qt Code:
    1. #ifndef CONNECTION_H
    2. #define CONNECTION_H
    3.  
    4. #include <QMessageBox>
    5. #include <QSqlDatabase>
    6. #include <QSqlError>
    7. #include <QSqlQuery>
    8.  
    9.  
    10. static bool createConnection()
    11. {
    12. QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    13. db.setDatabaseName("frezen");
    14. db.setHostName("localhost");
    15. db.setUserName("jan");
    16. db.setPassword("asdfgh");
    17. if (!db.open()) {
    18. QMessageBox::warning(0, ("Cannot open database"),
    19. ("Unable to establish a database connection.\n") + db.lastError().text());
    20. return false;
    21. }
    22. QSqlQuery query;
    23. query.exec("create table frezen (materiaal varchar(20), treksterkte varchar(20),"
    24. "freestype varchar(20), freesdiameter varchar(20), aantaltanden varchar(20),"
    25. "koeling varchar(10), freesbewerking varchar(20), snijsnelheid varchar(20),"
    26. "voedingpertand varchar(20), snedediepte varchar(10), snedebreedte varchar(10))");
    27.  
    28. return true;
    29. }
    30.  
    31. #endif
    To copy to clipboard, switch view to plain text mode 

    Here my code for inserting records
    frezen.cpp
    Qt Code:
    1. #include <QtGui>
    2. #include <QtSql>
    3. #include <QSqlError>
    4. #include <QSqlRecord>
    5.  
    6. #include "frezen.h"
    7. #include "frees.h"
    8.  
    9.  
    10. Frezen::Frezen(const QString &frezen, QWidget *parent)
    11. : QDialog(parent)
    12. {
    13. model = new QSqlTableModel(this);
    14. model->setTable(frezen);
    15. model->setSort(1, Qt::DescendingOrder);
    16. model->setEditStrategy(QSqlTableModel::OnManualSubmit);
    17. model->select();
    18.  
    19. model->setHeaderData(0, Qt::Horizontal, tr("Materiaal"));
    20. model->setHeaderData(1, Qt::Horizontal, tr("Treksterkte"));
    21. model->setHeaderData(2, Qt::Horizontal, tr("Frees type"));
    22. model->setHeaderData(3, Qt::Horizontal, tr("Frees diameter"));
    23. model->setHeaderData(4, Qt::Horizontal, tr("Aantal tanden"));
    24. model->setHeaderData(5, Qt::Horizontal, tr("Koeling"));
    25. model->setHeaderData(6, Qt::Horizontal, tr("Frees bewerking"));
    26. model->setHeaderData(7, Qt::Horizontal, tr("Snijsnelheid"));
    27. model->setHeaderData(8, Qt::Horizontal, tr("Voeding per tand"));
    28. model->setHeaderData(9, Qt::Horizontal, tr("Snedediepte"));
    29. model->setHeaderData(10, Qt::Horizontal, tr("Snedebreedte"));
    30.  
    31.  
    32.  
    33. QTableView *view = new QTableView;
    34. view->setModel(model);
    35.  
    36.  
    37. addButton = new QPushButton("Toevoegen");
    38. removeButton = new QPushButton(" Verwijderen");
    39. submitButton = new QPushButton(tr("Submit"));
    40. submitButton->setDefault(true);
    41. quitButton = new QPushButton("Afsluiten");
    42.  
    43. connect(submitButton, SIGNAL(clicked()), this, SLOT(submit()));
    44. connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));
    45. connect(addButton, SIGNAL(clicked()), this, SLOT(setData()));
    46. connect(removeButton, SIGNAL(clicked()), this, SLOT(deleteRow()));
    47.  
    48.  
    49. QVBoxLayout *buttonLayout = new QVBoxLayout;
    50. buttonLayout->addWidget(addButton);
    51. buttonLayout->addWidget(removeButton);
    52. buttonLayout->addWidget(submitButton);
    53. buttonLayout->addStretch(1);
    54. buttonLayout->addWidget(quitButton);
    55.  
    56. QHBoxLayout *mainLayout = new QHBoxLayout;
    57. mainLayout->addWidget(view);
    58. mainLayout->addLayout(buttonLayout);
    59. setLayout(mainLayout);
    60.  
    61. setWindowTitle(tr("Frezen"));
    62. resize (400, 400);
    63. }
    64.  
    65. void Frezen::submit()
    66. {
    67. model->database().transaction();
    68. if (model->submitAll()) {
    69. model->database().commit();
    70. } else {
    71. model->database().rollback();
    72. QMessageBox::warning(this, tr("frezen"),
    73. tr("The database reported an error: %1")
    74. .arg(model->lastError().text()));
    75. }
    76. }
    77.  
    78.  
    79.  
    80. void Frezen::setData()
    81.  
    82. {
    83. freesDialog dlg(this);
    84. if( dlg.exec() == QDialog::Accepted ) {
    85.  
    86. QString materiaal = dlg.matComboBox->currentText();
    87. QString treksterkte = dlg.trekComboBox->currentText();
    88. QString freestype = dlg.freesComboBox->currentText();
    89. QString freesdiameter = dlg.diaComboBox->currentText();
    90. QString aantaltanden= dlg.tandComboBox->currentText();
    91. QString koeling = dlg.koelComboBox->currentText();
    92. QString freesbewerking = dlg.freesbComboBox->currentText();
    93. QString snijsnelheid = dlg.snijComboBox->currentText();
    94. QString voedingpertand = dlg.voedingComboBox->currentText();
    95. QString snedediepte = dlg.snedeComboBox->currentText();
    96. QString snedebreedte = dlg.snedebComboBox->currentText();
    97.  
    98.  
    99.  
    100.  
    101. model->insertRows(0, 1);
    102. model->setData(model->index(0, 0), materiaal);
    103. model->setData(model->index(0, 1), treksterkte);
    104. model->setData(model->index(0, 2), freestype);
    105. model->setData(model->index(0, 3), freesdiameter);
    106. model->setData(model->index(0, 4), aantaltanden);
    107. model->setData(model->index(0, 5), koeling);
    108. model->setData(model->index(0, 6), freesbewerking);
    109. model->setData(model->index(0, 7), snijsnelheid);
    110. model->setData(model->index(0, 8), voedingpertand);
    111. model->setData(model->index(0, 9), snedediepte);
    112. model->setData(model->index(0, 10), snedebreedte);
    113.  
    114. return;
    115. }
    116.  
    117. }
    118.  
    119. void Frezen::deleteRow()
    120. {
    121.  
    122.  
    123. }
    To copy to clipboard, switch view to plain text mode 

    Thanks in advance
    Last edited by jacek; 21st March 2007 at 23:52. Reason: wrapped too long line

  2. #2
    Join Date
    Mar 2007
    Posts
    2
    Thanked 1 Time in 1 Post

    Default Re: QSqlite problem

    I also had some trouble with this in the past. I don't know all the details, but for some reason QT only seems to fetch 256 rows from the database, if more are present the behaviour you described arises.
    I do the following (after line 17 of your 2nd code block, with table instead of model)
    Qt Code:
    1. while (table->canFetchMore) {
    2. table->fetchMore();
    3. }
    To copy to clipboard, switch view to plain text mode 
    This makes sure that the entire table is correctly loaded.

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

    innerhippy (31st January 2009)

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

    Default Re: QSqlite problem

    Josbosmans is correct. It's because you are using a sqlite database with the QSqlTableModel. See the following for the solution Josbosmans described:

    http://doc.trolltech.com/4.2/qsqlque...html#fetchMore

    Also take a look at this post, go down to the bottom of message 6 in the thread:

    http://lists.trolltech.com/qt4-previ...ad00161-0.html

Similar Threads

  1. QTimer problem ... it runs but never triggs
    By yellowmat in forum Newbie
    Replies: 4
    Last Post: 4th July 2006, 12:54
  2. Grid Layout Problem
    By Seema Rao in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2006, 12:45
  3. Problem with bitBlt
    By yellowmat in forum Newbie
    Replies: 1
    Last Post: 5th April 2006, 14:08
  4. fftw problem
    By lordy in forum General Programming
    Replies: 1
    Last Post: 16th March 2006, 21:36
  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.