Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Multi-thread access QTreeView control

Multi-thread access QTreeView control

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    chcw
    wrote on last edited by
    #1

    In my application, there are two thread that may be access one QTreeView control at the same time. Are there any mechanism in QT that can lock the control in whole or just lock one tree node before the accessing, to prevent possible conflictions between two threads?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andreyc
      wrote on last edited by
      #2

      You can access Widgets directly only from "main thread":http://qt-project.org/doc/qt-5/threads-qobject.html#qobject-reentrancy

      [quote author="chcw" date="1408286029"]In my application, there are two thread that may be access one QTreeView control at the same time.[/quote]
      Do you mean you need to modify data that is shown in QTreeView?
      In this case you need to access the model of the QTreeView.

      To make it multithreaded add slots that will accept modification to the model.
      Connect then with the signals from both worker threads using "Queued Connection":http://qt-project.org/doc/qt-5/threads-qobject.html#signals-and-slots-across-threads

      If you steel need to synchronize the threads then "QMutex":http://qt-project.org/doc/qt-5/QMutex.html or "QMutexLocker":http://qt-project.org/doc/qt-5/qmutexlocker.html are at your service.

      [EDIT]: "Multithreading Technologies in Qt":http://qt-project.org/doc/qt-5/threads-technologies.html

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved