Results 1 to 2 of 2

Thread: QSqlQueryModel not updating when database changes

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QSqlQueryModel not updating when database changes

    QSqlQueryModel is read-only and reads only when setQuery() is called. Read-write models like QSqlTableModel track changes when they are made through the model.

    There is no single mechanism that Qt can use to receive notification from an underlying database engine about external changes that is supported or adaptable across all the databases supported by Qt. Oracle, Postgresql, and Sqlite have mechanisms to announce changes: all different of course. MySql has, AFAICT, no notification mechanism at all. ODBC is a generic abstraction that the Qt abstraction is built on top of: it seems unlikely notifications would make it through. Qt does not expose the notification mechanism in Sqlite if db.driver()->hasFeature(QSqlDriver::EventNotifications) is to be believed. If it were exposed you could use the QSqlDriver functions to subscribe.

    You can refresh your QSqlQueryModel by recalling setQuery() with the query(). Calling model->query()->exec() may work (I have not tried). You will probably lose selections in attached views and a few other things.

  2. The following user says thank you to ChrisW67 for this useful post:

    Momergil (31st March 2014)

Similar Threads

  1. Replies: 3
    Last Post: 3rd October 2011, 08:08
  2. QSqlite database lock + Delegate + QSqlQueryModel
    By NoRulez in forum Qt Programming
    Replies: 0
    Last Post: 13th October 2009, 11:52
  3. Replies: 1
    Last Post: 26th March 2009, 15:25
  4. Replies: 2
    Last Post: 26th March 2009, 08:43
  5. updating database
    By locus in forum Qt Programming
    Replies: 3
    Last Post: 27th January 2007, 05:54

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
  •  
Qt is a trademark of The Qt Company.