Results 1 to 4 of 4

Thread: how to disable views from a model

  1. #1
    Join Date
    Jan 2007
    Location
    The Hague, The Netherlands
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question how to disable views from a model

    I use a QSqlTableModel with several views. When processing large amounts of data - using insertRecord(), insertRow() or setData() - the automatic updating of the views costs much processor time. I am looking for a proper way to disable the views before processing data and (re)enabling them afterwards.

    I tried subclassing QSqlTableModel and the Views by adding a signal/slot enableView(bool). At enableView(false) the views remove the model by calling setModel(0) and they restore to the original model at enableView(true). This works fine and gains lots of time. The drawback is, that it limits the reusabiltiy of the views, and makes it impossible or difficult to use proxymodels.

    Any suggestions?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to disable views from a model

    Maybe you could implement a "batch update proxy model" and put it between the views and troublesome model? You could say to the proxy "from now on don't propagate the updates", do your updates and then say "pass all changes accumulated changes to the view".

    Of course easier said than done. It's easy to implement it for setData(), but there might be a problem with insertRow(). If you don't have much data, but a lot of changes, you can simply use modelReset() signal.

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

    zeeeend (9th September 2008)

  4. #3
    Join Date
    Jan 2007
    Location
    The Hague, The Netherlands
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to disable views from a model

    Thanks,

    found a simple way to stop the views from updating.

    myModel->blockSignals(true);

    ...process data ...

    myModel->blockSignals(false);
    myModel->reset();

  5. #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: how to disable views from a model

    Avoid resetting the model as it invalidates all selections and other things related to the views. If you have to block the signals, track what you change and emit proper signals after you update the model. It would be wiser to do it the way Jacek suggests, though.

Similar Threads

  1. Drag and drop between model views
    By larry104 in forum Qt Programming
    Replies: 20
    Last Post: 19th January 2008, 16:09
  2. 2 Views 1 Model
    By PrimeCP in forum Qt Programming
    Replies: 3
    Last Post: 2nd October 2007, 01:40
  3. Replies: 4
    Last Post: 20th September 2007, 13:11
  4. Logging to a file and using same model for diff views
    By steg90 in forum Qt Programming
    Replies: 4
    Last Post: 10th May 2007, 23:16
  5. Model Views and QLabel
    By naresh in forum Qt Programming
    Replies: 1
    Last Post: 20th February 2006, 15:14

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.