Project

General

Profile

Qt signals not working

Added by Dominik Baláž almost 7 years ago

Hi, I want to have in my application exactly one QObject, which controlls some QProcesses, which users can start. Problem is that when I want to catch signals from QProcess, they are totally ignored. I looked at wtwithqt example and after reimplementing it for my project the signal/slot work only when every user have their own QObject, but I want to have just one. Is there some easy way to do it?

Thanks

D.


Replies (1)

RE: Qt signals not working - Added by Wim Dumon almost 7 years ago

Hey Dominik,

Since Qt's signal/slot mechanism is tied to QThreads (and their event loops) and QObjects are also tied to QThreads in which they are created, it's important to understand exactly what signals you fire from what thread, and what qobject in what thread is the intended receiver. See http://doc.qt.io/qt-5/threads-qobject.html

Wt's model has no such magick, but it is not threadsafe. This means that you have to ensure that concurrent access to a signal cannot happen, for example by holding the WApplication::UpdateLock() of the session under consideration (the same condition applies to the widget tree as a whole: you have to hold the UpdateLock when working with a widget tree). Signalling with signal/slots between sessions is not possible, but we have a WServer::post() mechanism if you want to do this.

From what you say, I suspect that you'll need a QThread that handles your QObject's slots. In that slot, use WServer::post() to trigger events in the Wt sessions that are concerned.

Best regards,

Wim.

    (1-1/1)