PDA

View Full Version : Creating DLL with dialogs for Qt app



FuturePrimitive
20th September 2011, 18:11
Hello !

I am creating Qt application which should be able to load DLLs with Qt GUI (dialogs, forms) used as extension to the main App. I am facing problem with creating these dialogs. They obviously need QApplication but i dont want to make another one inside DLL since the dialogs then appear as completely separate App. Despite my effort ive had no luck so far to find any example or hints how to do this properly. Should i somehow pass QApplication pointer to the DLL? If this is the way how should i use the pointer inside DLL? I can provide more details if needed. Thanks in advance.

ChrisW67
20th September 2011, 21:36
Use the Qt Plugin mechanism to load your extension containing the classes representing your widgets into your application. Create instances of your extension widgets (using a factory method as the interface of the plugin perhaps) and use them. You need the QApplication instance to exist when you use (instantiate) the widget. Loading the plugin is not using the widget.

FuturePrimitive
21st September 2011, 20:19
Hello,

Thanks for the reply. I was looking on the plugins but i would like to make it possible with DLL. I found this article in archive : http://www.qtcentre.org/archive/index.php/t-2570.html
Im curious about exactly this phrase by wysota: "Maybe it's better not to create a QApplication inside the dll and just use the one provided by the main binary?"

It looks like it can be done easily since it is "usual" way to do it. But still i dont know how.

stampede
21st September 2011, 20:34
I think ChrisW67 answer is enough for what you are trying to do - users of the dll should use the factory method to create your custom widgets, by that time they already should have the QApplication instance up and running. If you need the QApplication instance yourself inside some custom class, just use QApplication::instance() method to retrieve it. The fact that your method is "placed" in separate dll is meaningless in that case, still it will be the same instance of QApplication, the one created by the user.

FuturePrimitive
21st September 2011, 21:51
So, theres no way of doing it without plugin mechanism? Sorry for maybe being stubborn bud in this case it would be better for me doing it the classic dll way.

ChrisW67
22nd September 2011, 00:21
The DLL is part of the same address space as your main application once loaded (by LoadLibraryEx on Windows). If you don't use the Qt plugin mechanism then you have to resolve names in the library yourself (GetProcAddress() on Windows) and do all the plumbing. Your "classic DLL", which differs from a Qt plugin only that it is more effort to manage and less portable, can call QApplication::instance() just the same as a routine in the main program exe.

If your "classic DLL" requirement is because you want to load the resulting DLL into a non-Qt program then you have a different issue, not the one you described in your first post, and not the one from your linked post.