My gut tells me you are asking for trouble
here. Qt is not designed (and neither are most application frameworks) to
have multiple instantiations.
Thus “hiding” an app inside a
dll seems a bit risky. From an architecture point of view, with
QApplication having a bunch of static members, your just asking for trouble.
And there is no way to prevent multiple applications from being created since
your inside a DLL…
That said, I don’t see any “main
widget” getting created or set for the application, so from your code
example, I don’t see how the event loop gets terminated.
(Calling quit don’t do it)
Take a look at the following code base, it
also hangs for what I think, is the same reason
class CFoobar : public QObject
{
public:
CFoobar()
: QObject()
{
qApp->quit();
}
};
int main(int argc, char ** argv)
{
QApplication
a( argc, argv );
CFoobar
foobar;
return a.exec();
}
If you could send a more complete code
example, we could probably be more help…
Scott
From: Jason Daniels
[mailto:jdaniels@xxxxxxxxxxxxxx]
Sent: Friday, November 18, 2005
1:13 PM
To: qt-interest@xxxxxxxxxxxxx
Subject: QApplication >From within
a DLL
I am trying to create a DLL that will make http calls using
QHttp. QHttp is asynchronous and relies on the Slots and Signals to give
back the responses. This requires that QApplication be instantiated
and executed at some point.
So here is my problem, if I instantiate QApplication from inside the
DLL - the slots are never executed and it appears as if the signals are never
fired off either. If I run this run main, it works perfectly. All
the docs seem to indicate that I should be able to create this QApplication
inside the DLL, but it isn't working for me. (NOTE: I will not be
able to call my DLL from inside a C main method and so it needs to be totally
self contained inside the DLL)
Any ideas on how to make this work will be greatly appreciated.
The code I am using to start everything is this:
extern "C" __declspec(dllexport) char* dllMethod(char* u,
char* k)
{
int argc = 1;
char* argv[1];
QApplication app(argc, argv, false);
//Initiates the http request with a http->get(...)
qHttpTest.requestURL();
//NOTE: after this is called - nothing happens
//NOTE2: In the readyRead slot I call QApplication::quit
int result = app.exec();
return "success"; //The code never reaches this
point..it is blocking on app.exec
}