PDA

View Full Version : Signal/Slot connection doesn't work across DLLs



Liachtei
26th March 2015, 10:27
Hello Guys,
I hope you can help me with a problem. I developed a Qt application with various DLLs on Visual Studio. When I try to send signals inside one DLL everything works fine. Now i want to send signals across dlls and now the receiving slot is never called. The connect return true and the signal is emitted correctly. I even debugged into the Qt code and verified that the pointers are always correct and that there is no other object involved.

The connection is here:

bool test = connect(sensor, SIGNAL(sendMessage(QByteArray)), channel, SLOT(receiveMessageForTransit(QByteArray)));

The signal emit is here:

const QByteArray msg = this->convertDataEntityToByteArray(type, rawData)
emit sendMessage(msg);


My export DLL code looks like:

#ifdef SENSORSUBSYSTEM_LIB
# define SENSORSUBSYSTEM_EXPORT Q_DECL_EXPORT
#else
# define SENSORSUBSYSTEM_EXPORT Q_DECL_IMPORT
#endif



The signal is emitted and Qt knows that there is a receiver connected to it. but the corresponding slot is never called. Do I have to do some extra exportor can somebody see an error in my export macro.

d_stranz
26th March 2015, 17:08
Signals and slots work across DLLs throughout a DLL-based installation of Qt; it makes no difference whether the DLL is one from Qt or one of your own, except the slot (or the class it is contained in) must be exported from the DLL (the Micro$oft dll_export / dll_import voodoo). You won't get linker errors using the SIGNAL() / SLOT() based method of making the connect. However, if you change to the new function pointer based syntax:


connect( somePointer, &SomeClass::someSignal, someOtherPointer, &SomeOtherClass::someSlot );

you'll know at link time if you've exported and imported things properly.

Another potential problem which you haven't posted enough code to determine - are you certain that the class instances you are connecting are the ones you think you are? In other words, if the lifetimes of the instances on either end of the connection don't last long enough, then the connection will automatically be deleted by Qt when one end goes out of scope.

Or have you fallen into the common mistake of instantiating a local variable that hides one of the same name at an enclosing scope, and connecting to that one instead of the one you think?