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. Marshal calls to Qt main thread
Forum Updated to NodeBB v4.3 + New Features

Marshal calls to Qt main thread

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 2.1k 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.
  • D Offline
    D Offline
    dreijer
    wrote on last edited by
    #1

    I'd like to wrap libcommuni, which uses Qt, in a different DLL project, which doesn't use Qt. As far as I've been able to tell, I need to run the Qt message pump (via QCoreApplication) to make sure networking, signals, etc. work properly. However, I'm running in to some problems figuring out how to do just that.

    Basically, I want to spin up a QThread in the DLL, which calls QCoreApplication::exec() and pumps all the Qt events. I then want to marshal external calls to the DLL, which are on a different thread, to the Qt main thread, so I can safely use libcommuni.

    It looks like the recommended approach is to use signals and slots for this, but I've been unable to get that to work. I create a signal on the QObject class that is called via the DLL and I connect it to a slot on the QThread that runs the Qt message pump. However, if I specify Qt::QueuedConnection when connecting the signal and slot, the message is never delivered when I emit the signal. If I omit Qt::QueuedConnection altogether, the slot is called immediately on the calling thread rather than the Qt main thread.

    I've also tried explicitly calling QCoreApplication::postEvent() on the DLL thread to send an event to the Qt main thread, but event(QEvent) is never called in the target QThread.

    Any ideas on what I'm doing wrong here? I'm thinking the issue might be that the signal is emitted from a non-QThread perhaps?

    1 Reply Last reply
    0
    • B Offline
      B Offline
      bodzio131
      wrote on last edited by
      #2

      Hi,
      I'm not sure but you can connect only QObjects created in QThread with event loop (thread of creation is important). Have you created mentioned QObject in QThread or DLL thread?
      There is probably similar dependency between postEvent and object which is calling this method: try to create QObject in your QThread and then use it to post event into QCoreApplication.
      Hope it helps.

      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