Results 1 to 8 of 8

Thread: The "best" way to refresh a QSqlQueryModel when the content of the query changes

  1. #1
    Join Date
    Oct 2009
    Location
    Vienna, Austria
    Posts
    57
    Thanks
    24
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default The "best" way to refresh a QSqlQueryModel when the content of the query changes

    I was wondering what the "most" correct way to refresh a QTableView using a QSqlQueryModel would be when the result of the query would change?

    I'm aware that:
    1) QSqlQueryModel ::setQuery can be called but why should I parse a new query just to refresh it?
    2) QTableView::setModel can be used but why should I set a new model only to refresh it?
    3) QSqlQueryModel ::reset can be used but this is a protected method and would completely reset the model including information about the header line etc.

    The model/view architecture of Qt seems to have a very complex and well documented architecture but I just cannot seem to find the "correct" way to do this.

    Thank you,
    D

  2. #2
    Join Date
    Apr 2010
    Location
    Rostov-na-Donu, Russia
    Posts
    153
    Thanks
    2
    Thanked 26 Times in 23 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: The "best" way to refresh a QSqlQueryModel when the content of the query changes


  3. #3
    Join Date
    Oct 2009
    Location
    Vienna, Austria
    Posts
    57
    Thanks
    24
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: The "best" way to refresh a QSqlQueryModel when the content of the query changes

    Quote Originally Posted by borisbn View Post
    When looking at the documentation of this signal (This signal is emitted whenever the layout of items exposed by the model has changed) it rather looks as if this signal would be emitted when the layout of the model is changed by the model to its views.
    It does not seem as if this would be what I'm looking for.
    Last edited by doberkofler; 6th April 2010 at 20:11.

  4. #4
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Thanks
    82
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: The "best" way to refresh a QSqlQueryModel when the content of the query changes

    Try QSqlTableModel instead, you can still use setQuery(), but you can also use model->select() to re-run it.

  5. The following user says thank you to waynew for this useful post:

    doberkofler (7th April 2010)

  6. #5
    Join Date
    Oct 2009
    Location
    Vienna, Austria
    Posts
    57
    Thanks
    24
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: The "best" way to refresh a QSqlQueryModel when the content of the query changes

    QSqlTable::select() would be exactly what I need but QSqlTable has it'slimitations.
    setQuery in QSqlTableModel is protected and according to the documentation setQuery should not be used.
    "This function simply calls QSqlQueryModel::setQuery(query). You should normally not call it on a QSqlTableModel. Instead, use setTable(), setSort(), setFilter(), etc., to set up the query"

  7. The following user says thank you to doberkofler for this useful post:

    waynew (8th April 2010)

  8. #6
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Thanks
    82
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: The "best" way to refresh a QSqlQueryModel when the content of the query changes

    Very good. Thanks for that information. Checking my project code, I see that I am only using setQuery() where I am using QSqlQueryModel, never with QSqlTableModel.

  9. #7
    Join Date
    Oct 2009
    Location
    Vienna, Austria
    Posts
    57
    Thanks
    24
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: The "best" way to refresh a QSqlQueryModel when the content of the query changes

    I'm still wondering what the "best" way for the refresh itself would be or is setQuery simply the only one?

  10. #8
    Join Date
    Mar 2013
    Posts
    1
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: The "best" way to refresh a QSqlQueryModel when the content of the query changes

    A little bit late, but in case someone comes across this thread in search for a solution (just like me a few minutes ago):
    Qt Code:
    1. model->query().exec()
    To copy to clipboard, switch view to plain text mode 
    This appears to be working well, I've even got two proxy models in between.

  11. The following 2 users say thank you to quarkthesecond for this useful post:

    Momergil (30th March 2014), vallidor (10th October 2013)

Similar Threads

  1. Replies: 1
    Last Post: 7th April 2010, 22:46
  2. Replies: 3
    Last Post: 15th February 2010, 18:27
  3. Replies: 4
    Last Post: 11th December 2008, 18:35
  4. Translation QFileDialog standart buttons ("Open"/"Save"/"Cancel")
    By victor.yacovlev in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2008, 20:05
  5. QFile Problem~ "Unknow error" in "open(QIODevice::ReadWrite)"
    By fengtian.we in forum Qt Programming
    Replies: 3
    Last Post: 23rd May 2007, 16:58

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.