PDA

View Full Version : Emitting signal from DLL to EXE



Miihkali
25th March 2009, 14:47
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:



#ifdef DLL_BUILD
# define DLL_EXPORT Q_DECL_EXPORT
#else
# define DLL_EXPORT Q_DECL_IMPORT
#endif


in dll's .pro file:



DEFINES += DLL_BUILD


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



class DLL_EXPORT MyDLL : public QObject
{
Q_OBJECT
...
signals:
void testSignal();


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?

wysota
26th March 2009, 08:26
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)?

Miihkali
26th March 2009, 08:42
Oops, sorry... I was so busy giving the overall description that I forgot to mention what is the actual problem :o

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.

wysota
26th March 2009, 10:07
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.

Miihkali
26th March 2009, 10:27
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 :confused:

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

Miihkali
26th March 2009, 14:47
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...

Miihkali
27th March 2009, 08:32
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 :o