Solved How to create and load UI plugins?
-
@raven-worx
Hello,
Maybe there is a misunderstanding. I fathomed IL's question to be that he wants to write plugins for his own program not for Qt. Then you define your interfaces and load your applications plugins with theQPluginLoader
class. TheQObject
you get is the actual plugin class that you query for functionality by means of the interfaces you've defined in your application (as it is done in the plug & paint example I've linked). There is noQGenericPlugin
plugin there. You just subclassQObject
and through the desired interfaces you provide the instances you need. TheQObject
is just an entry point for your plugin and your application has no knowledge of the implementation specific details. Your plugin on the other hand has to include the interfaces it's implementing (which is normal) but not the other way around. See here the low-level API I'm talking about.Kind regards.
-
yes, maybe this was a long shot from me.
But basically it's the same mechanism i was talking about.
Just Qt (QFactoryLoader) does most of the work under the hood automatically. -
@raven-worx
Hello and thanks,
Regarding your first comment/reply -
Quote:
Simply create a Lib project in QtCreator.
Now the question is if you want a- list itemshared library (linked dependency - program doesn't run without it), or
- list itema Qt-plugin (discovered and loaded at runtime - program also runs without it)
Then simply add a UI file manually to your QtCreator project.
Right click on your project -> Add New -> Qt -> Qt Designer Form Class
End of Quote
The second option is what I need, and I already did that but after adding UI into the QT plugin, the project doesn't compiled any more, it complain about missing files, like ui_<project-name>.h and more.- What is the correct way to do that?
Best regards,
IL -
try re-running qmake.
(Right click on project -> Run qmake) -
@raven-worx
same thing,
Running qmake is ok but build failed
it should at-least generate ui_project.h file but it doesnt do that. -
@IL
Do you have your forms in your project, like this:FORMS += myform.ui
I don't know what IDE you're using, for me QtCreator does this automatically, but it's possible it's different for you.
-
@kshegunov
Yes I do have the file in my form project.
The thing is when I create new QT widgets application project, QtCreator creat the file.ui file and under the output folder build-...-Debug it create a ui_file.h which contains all the UI stuff
But when I create QtPlugin library project and add UI form, the ui_file doesn't create eventhough it adding include of it.
I am working with QT-5.5.0 and Qt Creator 3.4.2Any idea?
-
@IL
When I go to the New file or project ... menu and then from the sidebar I select Library, I can choose from:- C++ library - this is what you actually want
- QtQuick 1 Extension plugin - this is for QtQuick (not relevant to your case)
- QtQuick 2 Extension plugin - this is for QtQuick 2 (not relevant to your case as well)
- Qt Creator Plugin - unless you want to create plugins for QtCreator, this is not your project type.
I don't have a QtPlugin library project in my list.
-
@IL
seems like this is a bug in Qt5's qmake. That the build steps are not created correctly when TEMPLATE=lib
It works perfectly fine in Qt4. -
@kshegunov
Good,
Now if you go to New Project and select C++ Library
Under Type you will have three options:- shared library
- statically linked library
- Qt Plugin
I choose the third option, can you see that?
-
@IL
Aha, I see what you mean. Well, you won't be extending Qt, but your application, so choose Shared Library from the dropdown, not Qt Plugin. -
@kshegunov
Yap, Thanks, Thanks. :-)
Now It's generate all the required files, I also need to add QWidgets in Select Required Models.Best Regards,
IL