Results 1 to 2 of 2

Thread: Signal/Slot connection doesn't work across DLLs

  1. #1
    Join Date
    Mar 2015
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Signal/Slot connection doesn't work across DLLs

    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:
    Qt Code:
    1. bool test = connect(sensor, SIGNAL(sendMessage(QByteArray)), channel, SLOT(receiveMessageForTransit(QByteArray)));
    To copy to clipboard, switch view to plain text mode 

    The signal emit is here:
    Qt Code:
    1. const QByteArray msg = this->convertDataEntityToByteArray(type, rawData)
    2. emit sendMessage(msg);
    To copy to clipboard, switch view to plain text mode 


    My export DLL code looks like:
    Qt Code:
    1. #ifdef SENSORSUBSYSTEM_LIB
    2. # define SENSORSUBSYSTEM_EXPORT Q_DECL_EXPORT
    3. #else
    4. # define SENSORSUBSYSTEM_EXPORT Q_DECL_IMPORT
    5. #endif
    To copy to clipboard, switch view to plain text mode 


    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.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,310
    Thanks
    244
    Thanked 678 Times in 668 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Signal/Slot connection doesn't work across DLLs

    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:

    Qt Code:
    1. connect( somePointer, &SomeClass::someSignal, someOtherPointer, &SomeOtherClass::someSlot );
    To copy to clipboard, switch view to plain text mode 

    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?

Similar Threads

  1. Replies: 2
    Last Post: 16th October 2011, 08:53
  2. Signal/Slot connection failing
    By Polnareff in forum Qt Programming
    Replies: 3
    Last Post: 15th July 2010, 21:41
  3. Signal and Slot connection not working !!
    By prakash437 in forum Qt Programming
    Replies: 3
    Last Post: 17th May 2010, 11:16
  4. Connection doesn't work
    By ^NyAw^ in forum Qt Programming
    Replies: 2
    Last Post: 20th March 2007, 13:09
  5. signal slot connection
    By Big Duck in forum Newbie
    Replies: 2
    Last Post: 4th July 2006, 14:31

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.