Results 1 to 4 of 4

Thread: how can I refresh QSqlQueryModel?

  1. #1
    Join Date
    Jun 2009
    Posts
    74
    Thanks
    23
    Thanked 2 Times in 2 Posts

    Question how can I refresh QSqlQueryModel?

    Hi,All

    I'am using QSqlQueryModel ,but I am wondering how can I refresh the data inside it,
    for example:
    //
    Qt Code:
    1. model->setQuery("SELECT name, salary FROM employee");
    2. model->setHeaderData(0, Qt::Horizontal, tr("Name"));
    3. model->setHeaderData(1, Qt::Horizontal, tr("Salary"));
    4.  
    5. QTableView *view = new QTableView;
    6. view->setModel(model);
    7. view->show();
    To copy to clipboard, switch view to plain text mode 
    //
    if I insert a row into employee using another application,
    how can i refresh the QSqlQueryModel?

    Thanks.
    Last edited by wysota; 15th June 2009 at 17:23. Reason: missing [code] tags

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

    Default Re: how can I refresh QSqlQueryModel?

    clear() the model and set the query again. By the way, in the above situation it is better to use QSqlTableModel.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    hashb (20th June 2009)

  4. #3
    Join Date
    Jun 2009
    Posts
    74
    Thanks
    23
    Thanked 2 Times in 2 Posts

    Default Re: how can I refresh QSqlQueryModel?

    Hi,wysota

    Thanks a lot for your help,
    I have tried it,but it seemed that the corresponding view did not update,any suggestions?

    Thanks,
    hashb

  5. #4
    Join Date
    Jun 2009
    Posts
    74
    Thanks
    23
    Thanked 2 Times in 2 Posts

    Smile Re: how can I refresh QSqlQueryModel?

    Hi,wysota

    I have made a mistake:
    QSqlQuery q = pModel_->query();
    pModel_->clear();
    pModel_->setQuery(q); // <--can not work

    change it to works:
    QSqlQuery q = pModel_->query();
    pModel_->clear();
    pModel_->setQuery(q.executedQuery()); //works now!!



    Thanks,
    hashb

Similar Threads

  1. Can't seem to get QGraphicsView to refresh
    By smahnken in forum Qt Programming
    Replies: 18
    Last Post: 29th August 2008, 08:32
  2. QSqlQueryModel fetchMore
    By skuda in forum Qt Programming
    Replies: 0
    Last Post: 17th July 2008, 19:42
  3. QSqlQueryModel speed problem
    By tbscope in forum Qt Programming
    Replies: 2
    Last Post: 23rd March 2008, 11:31
  4. Refresh QDataTable
    By shamik in forum Qt Programming
    Replies: 25
    Last Post: 1st December 2006, 05:04
  5. QSqlQueryModel + set Write
    By raphaelf in forum Qt Programming
    Replies: 7
    Last Post: 5th June 2006, 08:55

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.