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. Why modifying GUI from worker thread does not rise access violation
Qt 6.11 is out! See what's new in the release blog

Why modifying GUI from worker thread does not rise access violation

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 953 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.
  • T Offline
    T Offline
    theknight47
    wrote on last edited by
    #1

    Hi,

    I tried to update a GUI from a worker thread and strangely no exception is caught and the GUI is modified normally. However, I have randomely some access violation from Qt5GUI.dll.

    I want to know if that is possible ( that modifying a GUI from background thread may work ) and please explain me how the access violation occurs is this case.

    Thank you in advance.

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Moderators Qt Champions 2024 Qt Champions 2022 Qt Champions 2017
      wrote on last edited by
      #2

      Yes it is possible. Nothing stops from you doing this. Can you tell me the run time error you hit when access violation happens ? It must be failing with 'sendEvent(...) method when you access the UI from other thread.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      https://www.pthinks.com

      1 Reply Last reply
      2
      • JKSHJ Offline
        JKSHJ Offline
        JKSH
        Moderators
        wrote on last edited by
        #3

        Modifying the GUI from a worker thread is not an access violation. However, it often causes data corruption. Qt's GUI classes are not "synchronized":http://doc.qt.io/qt-5/threads-synchronizing.html so it is not safe to modify them from different threads.

        Your worker thread should do one of the following:

        Emit a signal, to run a slot in the GUI thread, OR

        Use QMetaObject::invokeMethod() to run a slot in the GUI thread

        [quote author="Dheerendra" date="1425395696"]Yes it is possible. Nothing stops from you doing this.[/quote]No it's not. See the "documentation":http://doc.qt.io/qt-5/threads-qobject.html -- "GUI classes, notably QWidget and all its subclasses, are not reentrant. They can only be used from the main thread."

        Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

        1 Reply Last reply
        1

        • Login

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