PDA

View Full Version : adding a qt-ui to a non-qt project, dll



TheKedge
28th February 2007, 11:32
Hello all,
I'm doing some refactoring. I have a non-gui, non-qt dll (MSVC), to which I've added a qt class which derives from QWidget. (this widget should give me some access to the other parts of the dll)

I've got no .pro file and haven't used qmake. Everything compiles wonderfully, runs perfectly and crashes as expected - "QWidget: Must make a QApplication before..." when asked to show the UI.

What can I do to get the thing Qt'd?

What do I need to put into DllMain() - like in main(){ QApplication app(argc, argv); ...

can I do it without a *.pro?

thanks
K

wysota
28th February 2007, 11:48
You need a running event loop to be able to handle the widget. So you need to create QApplication and then run its exec(), but this will block the rest of your application (along the WinAPI event loop). Alternatively you can use some WinAPI calls to start a timer, which will call QApplication::processEvents() every now and then.

TheKedge
28th February 2007, 11:52
ok, thanks for the info,

I think I need a different plan...
K

Eldritch
28th February 2007, 17:08
The requirement for a QApplication is often a 'gotcha' on this kind of thing. Dealing with that can be relatively easy (as it probably is in your case).

It gets a little trickier if you have a UI-application that's not Qt that needs to incorporate DLLs built w/ Qt. And if your DLL is generally distributed, the potential exists for it to be loaded by a Qt application as well. :eek: Then, presuming DLL linkage and not static linkage to Qt, you get bitten by the singleton requirement of QApplication.

I haven't tried the timer w/ occasional processEvents() call.

Rather, in my case, we spin up a new thread specifically to run the Qt UI on so it won't interfere with the message pump in the 'main' part of our application. It turns out that having two different entities thinking they control the message pump is ... problematical. ;)