Custom Plugins
-
I apologize if this has been asked before, but I am hoping someone can point me in the right direction. I would like to create my own plugins. I've created ones before in previous versions (5.3 I believe?) and when I used them in an application, the application ran without any problems.
I am now using QT 5.7. Looking at the Analog Clock example (http://doc.qt.io/qt-5/qtdesigner-customwidgetplugin-analogclock-h.html) I compiled the plugin successfully, and the .dll was created. I put the .dll in the plugins/designer folder in the QT build. I create an application and use the Analog Clock on the application form. However, when I go to run the application, I get an error "Undefined reference to '__imp___ZN11AnalogClockC1EP7QWidget' "
On the plugin side, I deleted the QDESIGNER_WIDGET_EXPORT under the analogclock.h file and changed the include to <QtUiPlugin/QDesignerCustomWidgetInterface>
and after recompiling, placing the new .dll in the QT build, when I run the application the error gets cleaned up to "Undefined reference to AnalogClock::AnalogClock(QWidget*)' "
Am I missing an include file on the application side? Any help is much appreciated. Thanks.
-
Hi and welcome to devnet,
Likely because the .dll can't be found at runtime for your application since it's in the designer folder.
Are you following the "monolithic" approach for your plugin ?
-
Well, my goal is to create custom plugins that can be used in future applications. Because of the nature of my job, I can't talk about specifics. I've created custom plugins before in previous versions. My process then was:
- Design the plugin
- Compile/Build the project, which then creates the .dll
- Copy the .dll to the plugins/designer folder
- Create a new application window that uses the custom plugin
This worked perfectly for me before. All I had to do then was include my plugin class in the application header file.
I know that some #includes for the plugins have been deprecated and you now have to use <QtUiPlugin/QDesignerExportWidget> but I still don't understand why I'm getting the "Undefined reference" error.
To keep things simple, take this example (http://doc.qt.io/qt-5/qtdesigner-customwidgetplugin-example.html)
What are the step-by-step instructions to use this plugin, starting from building the plugin itself. Is there anything special I need to do to the plugin project? Do I need to copy the .dll to a different location? Is there anything extra I need to include in the application project that uses the plugin?
-
Thank you very much, that worked. May I ask how this is different from doing #include <plugin class> within the application header file?
Also, I ran into another error when running the application:
--This application failed to start because it could not find or load the QT platform plugin "windows" in " ". --After some research, I had to include the qwindows.dll in a platforms folder within my application release folder. Is there an easier way of doing this rather than having to copy that .dll every time I use the plugin in an application?
-
Doing so you separate things cleanly. The plugin becomes another in dependent project using the same library as your application.
You can use windeployqt to automate that part.
-
Ahh, I see, that makes sense. Thank you so much for your help!
Also, I've found that adding an environment variable:
QT_QPA_PLATFORM_PLUGIN_PATH : <path to qt platforms/qwindows.dll>
This gets rid of the error. It is a lot easier than having to add the .dll in each application project.
Again, thank you so much for your help!