Results 1 to 1 of 1

Thread: QTableView and QSqlQueryModel. Strange problems

  1. #1
    Join Date
    Jul 2007
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QTableView and QSqlQueryModel. Strange problems

    I'm writing a small utility. It have QTableView connected with QSqlQueryModel. DB is SQLite3. When somebody inputs text calls findText:
    Qt Code:
    1. void student::findText(const QString & text)
    2. {
    3. QString newText=text;
    4. if (weShouldIgnoreSpaces())
    5. newText.replace(QString(" "),QString("%"));
    6. modelQuestion->setQuery("SELECT * FROM Question WHERE QuestionText LIKE '%"+newText+"%' ORDER BY idQuestion");
    7. if (modelQuestion->lastError().isValid())
    8. qDebug() << modelQuestion->lastError();
    9. modelQuestion->setHeaderData(0, Qt::Horizontal, tr("Question ID"));
    10. modelQuestion->removeColumns(1,2);
    11. modelQuestion->setHeaderData(1, Qt::Horizontal, tr("Question Text"));
    12. modelQuestion->removeColumns(2,2);
    13. <...>
    14. }
    To copy to clipboard, switch view to plain text mode 
    (it is part of code).

    It seems that it works, but if you write "OSI HUBa" and then delete "a" you'll get what is in attach1 instead of attach2.
    If I add
    Qt Code:
    1. delete modelQuestion;
    2. modelQuestion = new QSqlQueryModel(0);
    3. questionOutput->setModel(modelQuestion);
    To copy to clipboard, switch view to plain text mode 
    somewhere before modelQuestion->setQuery it works normaly. But I don't think that it is normal behavior.
    I think the problem is in my code. But I don't know exactly where.
    Any ideas?
    Attached Images Attached Images
    Last edited by Civil; 3rd April 2008 at 19:48.

Similar Threads

  1. QTableView, QSqlQueryModel and delegates
    By estanisgeyer in forum Qt Programming
    Replies: 1
    Last Post: 29th January 2008, 12:04
  2. [Qt 4.1] Strange behaviour with QTableView
    By fane in forum Qt Programming
    Replies: 1
    Last Post: 23rd January 2006, 06:17

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.