Results 1 to 4 of 4

Thread: Informing a model its data has changed

  1. #1
    Join Date
    Jan 2007
    Location
    The Netherlands
    Posts
    15
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Informing a model its data has changed

    Hi all,

    I'm using 2 models (a QSqlRelationalTableModel and a QSqlTableModel) working on the same data. One is used to display only some columns of the table and it allows people to click on the item which causes all the data from the table to be loaded in a different section of the screen using all sorts of widgets (LineEdit, DateEdit etc.).

    The problem is that I'd like to inform the model used to display the list of items when the data is changed and saved in the other model. Currently I'm executing a simple select() but this reloads the entire table while only the data in a single row has changed. Is there a way I can optimize this to only make the model reload a single row?

  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: Informing a model its data has changed

    Use a proxy model instead of the smaller model to select only a subset of the original model data. You can also use the dataChanged() signal from the model to inform the other that some data has changed, but this is tricky as you'll need another layer for translating indexes, so using a proxy model should be much easier.

  3. #3
    Join Date
    Jan 2007
    Location
    The Netherlands
    Posts
    15
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Informing a model its data has changed

    That indeed seems like the way to do it, though I do have a question.

    Like I said in my previous post, I have a relation between 2 tables and one model uses it while the other doesn't. That's the reason I created 2 models in the first place. So the QSqlRelationTableModel which is used in the list with only a subset of the columns displayed shows the value of the joined table while the QSqlTableModel uses the id and passes it to a QComboBox.

    So how should I get this behaviour with a proxy model? Can I modify the query of the sourcemodel or proxymodel to select both the value from the joined table and the id of the parent table. Is there a best practice to do this?

  4. #4
    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: Informing a model its data has changed

    You can have data from the other table (referring to the foreign key in the sql model) downloaded into the proxy model and simply "implement" the relation yourself - return data from the other table according to the id taken from the source model.

Similar Threads

  1. QSqlQueryModel data update
    By psi in forum Qt Programming
    Replies: 4
    Last Post: 20th July 2012, 03:59
  2. Modify model data in QTreeView
    By YuriyRusinov in forum Qt Programming
    Replies: 6
    Last Post: 26th October 2006, 17:28
  3. speed of setdata - lots of items in treeview
    By Big Duck in forum Qt Programming
    Replies: 4
    Last Post: 6th July 2006, 12:53
  4. Model, view, resize to show all data
    By jcr in forum Qt Programming
    Replies: 2
    Last Post: 17th April 2006, 20:59
  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.