Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

signal slot connections without QApplication or QCoreApplication

Tags:

windows

dll

qt

I would like to code a DLL which should be loaded by a non-QT application. As a result when my DLL is loaded I dont have any QApplication/QCoreApplication. As a result my Signal/Slot mechanism is not working.

I searched deeply in Qt forums but couldnt achieved a good answer yet about how to handle such a problem. I created a QThread moved my QObjects to that thread and created a fake QApplicationCore and called its exec() function inside QThread's run() function. This way my Signal Slot mechanism worked but I am not happy with that indirect solution. I should be able to activate my threads slots from the main non-Qt thread's execution space. What is the correct way of working with such dll plugins? Direct answers and reading source reccomandations are welcomed. Thank you

Note: The external application loading my DLL is a Windows app. It's a third party application and I cannot touch it.

like image 972
karadaga Avatar asked Dec 28 '12 09:12

karadaga


People also ask

How to connect signals and slots in QML?

Connecting signals inside QML files 1. Connect a signal to a signal 2. Using Variables in Signals 4. Conclusion Let's create our first class that will work with signals and slots in QML. This is one of the very first examples that I have already shown, but I will repeat this example so that the article is as complete as possible.

What is Qt signal and Qt slot concept?

With the Qt signal and Qt slot concept, Qt takes a slightly different approach. This Concept has the advantage that Qt automatically disconnects if one of the communicating objects is destroyed. This avoids many Crashes because attempts to access a nonexistent object do not more are possible.

What are QObject signals and slots?

Signals and slots can take any number of arguments of any type. They are completely type safe. All classes that inherit from QObject or one of its subclasses (e.g., QWidget) can contain signals and slots. Signals are emitted by objects when they change their state in a way that may be interesting to other objects.

What is the use of qcoreapplication?

The QCoreApplication class provides an event loop for Qt applications without UI. More... This class is used by non-GUI applications to provide their event loop. For non-GUI application that uses Qt, there should be exactly one QCoreApplication object. For GUI applications, see QGuiApplication.


1 Answers

Qt signals & slots require an event loop to be running. You have to run an event loop in the thread your QObjects exist. Of course you cannot run it in main thread of your application (as it does not use Qt), so, right, starting a QThread, moving your QObjects to this thread (or create these objects in run() method) and running exec() in thread's run() method is a correct solution.

like image 92
Archie Avatar answered Oct 21 '22 22:10

Archie