Results 1 to 3 of 3

Thread: both two slots modify data model, use lock to sync?

  1. #1
    Join Date
    Oct 2012
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default both two slots modify data model, use lock to sync?

    two threads emit two different signals to main thread two slots, both two slots modify data model, I'm using lock to sync, and testing now. So far no problem. Is this the right design?

    Thanks,

  2. #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: both two slots modify data model, use lock to sync?

    Starting two threads on the same problem will not increase the odds of an answer.

    The answer is a resounding "Maybe". Using signals/slots to carry data between threads is good; with copies being transmitted and queued. You should not need locking mechanisms if all your data structures are only accessed from the owning thread (e.g. in slot code). There are devils in the detail though... and we cannot see the detail.

  3. #3
    Join Date
    Oct 2012
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: both two slots modify data model, use lock to sync?

    Thank you Chris. Make sense. Since the two slots are in the same thread, it is not possible that they will be called and access the data model at the same time. so no need to use lock.

    Could you please have a look at my another design question:
    http://www.qtcentre.org/threads/5178...multithreading

    thanks,

Similar Threads

  1. Replies: 9
    Last Post: 14th February 2013, 20:39
  2. How to lock data petition for a custom model ?
    By tonnot in forum Qt Programming
    Replies: 5
    Last Post: 2nd November 2011, 09:32
  3. Modify c++ model data from QML Repeater
    By laszlo.gosztola in forum Qt Quick
    Replies: 7
    Last Post: 19th October 2011, 15:35
  4. QSql Model-View: How to keep view in sync with model
    By schall_l in forum Qt Programming
    Replies: 1
    Last Post: 23rd December 2008, 00:31
  5. Modify model data in QTreeView
    By YuriyRusinov in forum Qt Programming
    Replies: 6
    Last Post: 26th October 2006, 18:28

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.