Results 1 to 7 of 7

Thread: Emitting signal from DLL to EXE

  1. #1
    Join Date
    Mar 2009
    Posts
    13
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Emitting signal from DLL to EXE

    I'm developing application for Windows. I have an exe and a dll. In dll I try to emit a signal, and in exe I have a slot that should receive it. If I implement the slot method in dll instead of exe, it works just fine.

    By searching previous posts I understood that problem lies within exporting dll, but as I tested those solution they didn't fix the problem. From exe I can instantiate an object that is defined in dll, and 'normal' method calls are passed with no problems.

    So, what I did is the following:

    in a .h file included in dll:

    Qt Code:
    1. #ifdef DLL_BUILD
    2. # define DLL_EXPORT Q_DECL_EXPORT
    3. #else
    4. # define DLL_EXPORT Q_DECL_IMPORT
    5. #endif
    To copy to clipboard, switch view to plain text mode 

    in dll's .pro file:

    Qt Code:
    1. DEFINES += DLL_BUILD
    To copy to clipboard, switch view to plain text mode 

    ...and finally in dll's class description:

    Qt Code:
    1. class DLL_EXPORT MyDLL : public QObject
    2. {
    3. Q_OBJECT
    4. ...
    5. signals:
    6. void testSignal();
    To copy to clipboard, switch view to plain text mode 

    Is there something that I'm missing? Slots, signals and connections should be OK, at least they work if implemented inside the dll. The only thing that I'm unsure of is that is it OK to use Qt::AutoConnection connection type in connect method?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Emitting signal from DLL to EXE

    The connection should work fine. What exactly is the problem? Did you check your console logs for warnings from Qt (you might have to enable the console for that)?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Mar 2009
    Posts
    13
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Emitting signal from DLL to EXE

    Oops, sorry... I was so busy giving the overall description that I forgot to mention what is the actual problem

    The signal in dll is connected into a slot in exe. The problem is that when I emit the signal, execution never goes to slot method. And as I mentioned in the original post, if I implement the slot method in dll everything works just fine, so I guess that connection etc. should be OK.

    I've checked the console and there are no suspicious debug prints neither when compiling nor run-time.

    edit: Hmm, as I read your reply more carefully I noticed you talked about console logs... is there a way to get more comprehensive logs from Qt than regular debug prints? If yes, that I haven't done.
    Last edited by Miihkali; 26th March 2009 at 08:46.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Emitting signal from DLL to EXE

    No, I meant the debug statements. If there are no run-time warnings about signal/slot connections and you do have console turned on (CONFIG+=console on Windows) then the connection is probably established. You can check that by looking at the return value of connect(). Maybe the problem is elsewhere, for example the object containing the signal or the object containing the slot is destroyed before the signal emission takes place? Also make sure the signal indeed gets emitted.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Mar 2009
    Posts
    13
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Emitting signal from DLL to EXE

    I believe you're right, the problem seems to be somewhere else... I just created a test application which works exactly in a same way but does nothing extra, and everything seems to be ok

    Well, back to the drawing board... Thanks for the tips, I'll let you know if I find the problem source.

  6. #6
    Join Date
    Mar 2009
    Posts
    13
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Emitting signal from DLL to EXE

    Blah, still having the same problem...

    I implemented a method in the dll for testing this. The method does nothing but simply emits the signal.

    Well, here's the weird part: If i call that method from exe, everything works fine. Signal is emitted and a slot method in exe catches it. However, if I call the very same method from dll, it seems that nothing happens.

    I don't know if the signal is emitted, but for sure it's not received in the slot function. I guess I should have a look at the QSignalSpy class...

  7. #7
    Join Date
    Mar 2009
    Posts
    13
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Emitting signal from DLL to EXE

    Oh well, finally figured this one out. The problem was that elsewhere in the code there was created another instance of the class in the dll, and that was the one emitting the signal that I was supposed to catch in the exe. However, it wasn't the one that I had connected...

    I'll get me coat

Similar Threads

  1. Emitting signal causes CRASH
    By navi1084 in forum Qt Programming
    Replies: 7
    Last Post: 12th March 2009, 16:17
  2. pthread instead QThread
    By brevleq in forum Qt Programming
    Replies: 8
    Last Post: 23rd December 2008, 07:16
  3. Connection of custon signals/slots
    By brevleq in forum Qt Programming
    Replies: 2
    Last Post: 23rd December 2008, 07:04
  4. Replies: 3
    Last Post: 15th April 2007, 19:16
  5. cost of emitting signal
    By quickNitin in forum Newbie
    Replies: 1
    Last Post: 29th November 2006, 08:53

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.