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. Is it Ok to emit a signal from a thread?

Is it Ok to emit a signal from a thread?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 262 Views
  • 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.
  • B Offline
    B Offline
    BKBK
    wrote on last edited by
    #1

    My application is Qt based and has an Open GL widget. It runs under Centos Linux and uses a Linux pthread to capture data. My understanding is that the thread must not do anything that directly or indirectly updates any display.
    Does this same concept apply to emitting signals?
    I suspect that this line of code:
    emit favorite_signal( x );
    Sets a flag that causes the Qt engine to make the function call, provided there is a connect for that signal. If that is the case, it might be okay to emit signals from thread called code.
    I found something that might indirectly answer the question in that signals just call QMetaObject::activate but am uncertain if I interpret that correctly.

    1 Reply Last reply
    0
    • fcarneyF Offline
      fcarneyF Offline
      fcarney
      wrote on last edited by
      #2

      Signals and slots employ mutexes and can be used to communicate between threads. Just make sure you pass by value or have mutexes to guard data access if passing by other means. I have had issues passing by reference so I am not sure it can be done.

      You can even use slots to communicate to objects inside threads, however you need to be evaluating the Qt event loop inside that thread if you do so.

      C++ is a perfectly valid school of magic.

      1 Reply Last reply
      2

      • Login

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