PDA

View Full Version : Using widgets in dll, how to bind events to qApp



montuno
7th March 2008, 15:09
Hello...

foremost, yes I know, there are a lot of similar questions in this forum, but I was unable to find a solution that suit my needs.
For my project it would be very nice to carry out some widgets into a dynamic library. Obviously that I ran into the "...Must construct a QApplication before a QPaintDevice.." error (qwidget.cpp)

My question is: How can I tell these widgets where to find the main event-loop?
My idea was (of course after reading tfm :o) to link QApplication::instance() to somewhat, but how? And where?
Is QAbstractEventDispatcher a useful alternative?

Thanks for any hints

(yes, I am new to c++ and qt and... certainly I working on myself to make some progress :-) to avoid such questions and to help others, maybe??)

wysota
7th March 2008, 15:16
Where do you want to use that DLL? In some other Qt application or in a non-Qt app? If the latter, then you need to construct a QApplication object in the DLL and make sure it gets some CPU time from time to time to process the events. It's best to write a custom event dispatcher that would seamlessly blend with the event loop of the application (the same way as Qt uses the GLib event loop on Linux).

montuno
7th March 2008, 15:32
Outstanding.. I not expect such a quick answer!

No, its a Qt application. I carry out only for structural reasons. Do I need a custom event dispatcher in this case too?

wysota
7th March 2008, 15:39
Outstanding.. I not expect such a quick answer!
Lol... thanks :)


No, its a Qt application. I carry out only for structural reasons. Do I need a custom event dispatcher in this case too?

No, in that case just make sure you have a QApplication object in the application and don't create any static widgets or pixmaps. If you create those all objects on request, everything will work just fine (after all Qt itself is a set of libraries as well).

montuno
7th March 2008, 16:39
hmm... as you note the term 'static' somewhat rings somewhere...:o

I'm afraid my 'clever' 'object-factory' is not really clever: its only a sample but I was curios about creating widgets wich I only know at runtime..

hmm.

so far, thanks a lot wysota. I'll have a look. I let you and the others know about this issue

montuno
10th March 2008, 13:45
<info>
hmm, actually, it seems this behaviour appears only if I link against the Qt-debug libs (e.g. QtCored4.lib). No idea why.
</info>

Solution: My mistake was that I linked against another dll wich was created in release configuration. (typical newbie-bug I think)

>> Mod: you can delete this thread if you want.