PDA

View Full Version : Loading DLL that creates GUI.



The Storm
1st December 2008, 11:46
Hello again...

The issue this time is really weird. I have a Qt application that works good. I want to extend it via dynamic loading of DLLs. I do not use the Qt way from the documentation because of some reasons...

Here's what I do: I export a C function from the DLL, then I load that DLL from my Qt application. So far so good, the function in the DLL is called correctly but when comes time the DLL to create some kind of GUI it crashes directly with reason that QApplication must be initialized before QPaintDevice. Well in to the my main() function I initalise QApplication and any GUI that is created by the main program is working good, but I can't create GUI from the DLL. Did someone have any idea how to pass this problem? :)

The Storm
1st December 2008, 18:17
I forgot to mention - the Qt version is 4.4.3, Compiler is VC++ 2008, OS is Windows XP SP3 and the Qt is build as static. The error I get is "QWidget: Must construct a QApplication before a QPaintDevice" but as I already told QApplication is the first thing intalized in to the main() function of my application. The problem seems to be that in the DLL the qApp pointer is not valid o_0. It is not problem to pass this pointer in to the exported C function when I am loading the DLL but I do not see a way to set it in order to get qApp to return correct pointer. Please help.

spirit
1st December 2008, 18:20
you must create QApplication for providing event loop.

The Storm
2nd December 2008, 07:07
But yes I do in to the my application, it is the first thing I do:



int main(int argc, char *argv[])
{
QApplication app( argc, argv );
// code...
return app.exec();
}


But when I load the DLL using QLibrary to resolve a C exported function and when the times come for the DLL to create any kind of GUI it crashes with the error that I wrote above. Maybe I have to initialize QApplication again in to the DLL ? But then I will have two event loops and perhaps the GUI created via the DLL will be modal but I do not want to be modal. Any solution will be highly appricated. :)

spirit
2nd December 2008, 07:11
are you sure that methods which you export are valid, i.e. not null pointer?

The Storm
2nd December 2008, 07:43
Sure, via the DLL I can work with files and do everything that I want, except to create GUI...



extern "C" Q_DECL_EXPORT IPlugin* createPlugin( int tlsIndex )
{
g_core = new Chat();

g_idxThisThread = tlsIndex;

PluginImpl* plugin = new PluginImpl();

g_core->setPlugin( plugin );

return plugin;
}


This is the exported function from the DLL and it return correct pointer and the constructor of Chat() will do some stuff but when it come time to create the GUI it crashes.

The problem is that the DLL can't get valid qApp pointer witch is very strange, in to the main program there is no problem.

spirit
2nd December 2008, 07:53
is your app which uses this dll written on Qt?

The Storm
2nd December 2008, 08:16
Yes and in it the QApplication is initalized.

spirit
2nd December 2008, 08:19
so, why do you use QLibrary insted of adding your dll to your project?

The Storm
2nd December 2008, 08:38
What do you mean ? I want to load it dinamyc at runtime, thats why I use QLibrary to resolve the C exported function and activate the DLL in order to do the stuff.

The Storm
3rd December 2008, 07:38
Update: same thing happens on linux (.so). I created new QApplication instance in to the DLL but the event loop located in to the main executable have stucked. Please help.

The Storm
3rd December 2008, 18:19
With a 15 pages that the search of the forum returned, I finally found topic that answer to my question:
http://www.qtcentre.org/forum/f-qt-programming-2/t-plugin-and-internationalization-631.html

The other question is even if I pass the pointer of qApp to the DLL from the interface, how I will be able to set correct pointer to QApplication::instance(), I can't find a set method, tomorow I will try some things... If anyone have an idea in the mean time, please let me know.