PDA

View Full Version : Dynamic UI loading with custom widgets.



z80
13th June 2012, 14:01
Hello!
My problem is the following. I'd like to load UI files dynamically using QUiLoader::load(). As far as I have custom widgets I have to let me my application know about them. But I'd like to make it "single file application". As far as I understand I have to register my custom widget as a plugin using subclassing from QDesignerFormEditorInterface and registering that subclass with Q_EXPORT_PLUGIN2 macro and using Q_IMPORT_PLUGIN in the beginning of my application.

It must be I'm wrong because I get

..\..\lua-application\src\main.cpp(12) : warning C4101: 'qt_plugin_instance_widgets' : unreferenced local variable

at the line there Q_IMPORT_PLUGIN is mentioned and

error LNK2019: unresolved external symbol "class QObject * __cdecl qt_plugin_instance_widgets(void)" (?qt........

after linking attempt.

It must be it should be done in the way other then using Q_EXPORT_PLUGIN2/Q_IMPORT_PLUGIN couple. Could one, please, assist me with this issue? Sould it be made without separate shared plugin library?

Thank you in advance!

amleto
13th June 2012, 17:30
I don't think you are correct. That is what you need to do for making widgets available in Qt designer.

Have you seen this?
http://doc.qt.nokia.com/4.7-snapshot/designer-customwidgetplugin.html
It says that Q_EXPORT_PLUGIN2 is for using custom widget in Designer - not what you want.

This (http://doc.qt.nokia.com/4.7-snapshot/plugins-howto.html) tells you how to make a plugin for use in application.

Have you seen this?
http://qt-project.org/doc/qt-4.8/designer-calculatorbuilder.html
It shows how you can load ui with no plugin needed.

z80
14th June 2012, 14:42
I don't think you are correct. That is what you need to do for making widgets available in Qt designer.

Have you seen this?
http://doc.qt.nokia.com/4.7-snapshot/designer-customwidgetplugin.html
It says that Q_EXPORT_PLUGIN2 is for using custom widget in Designer - not what you want.

This (http://doc.qt.nokia.com/4.7-snapshot/plugins-howto.html) tells you how to make a plugin for use in application.

Have you seen this?
http://qt-project.org/doc/qt-4.8/designer-calculatorbuilder.html
It shows how you can load ui with no plugin needed.

Well, yes I've seen both links you've kindly provided. But the problem I've described appears because the UI file I try to load contains nonstandard Qt widget. When I make UI of standard widgets as at article you've provided I also don't experience any problem. But when I do, I don't know how to make QUILoader know about my custom widget without making separate QtDesigner plugin.

wysota
14th June 2012, 15:41
Override QUiLoader::createWidget() and handle those widgets yourself. Of course you'll have to link with respective classes (without using any plugins).

z80
19th June 2012, 08:03
Yes, I afraid that is the only possibility to do that without separate shared libraries.

wysota
19th June 2012, 09:53
Why are you "afraid"? This seems like a very nice solution.