Qt Plugins Not Working
I've created a custom widget plugin. The plugin integrates fine with Qt Creator but when I compile the program, I'm getting this error:
"test.h: No such file or directory"
Where test.h is the name of the custom widget. What am I doing wrong? This is the *.pro file of the application:
TEMPLATE = app SOURCES += main.cpp \ mainwindow.cpp HEADERS += mainwindow.h FORMS += mainwindow.ui
This is the *.pro file of the plugin:
CONFIG += designer plugin debug_and_release TARGET = $$qtLibraryTarget(testplugin) TEMPLATE = lib HEADERS = testplugin.h SOURCES = testplugin.cpp RESOURCES = icons.qrc target.path = $$[QT_INSTALL_PLUGINS]/designer INSTALLS += target include(test.pri)
After extensive research, I stumbled upon this thread:
It turns out that when you compile a plugin, the "dll" that you get is only for Qt Creator/Qt Designer integration purposes. You CANNOT link against that library. You should provide another library that contains the headers and the source code or include them in your project. So, to sum up, here are the proper steps to deploy a custom widget:
- Create a library containing the custom widget's sources and headers. Let's call this library A. Alternatively, add the sources and headers to your project.
- Create the widget plugin for Qt Creator/Designer integration. Again, this plugin is NOT usable for anything other than Qt Creator/Designer integration.
In your project, you must add the following lines to the *.pro file:
LIBS += C:\[PATH TO LIBRARY'S A BINARY] INCLUDEPATH += C:\[PATH TO LIBRARY'S A HEADERS]
Notice once again that you are linking to library A, NOT to the library that you get when you compile the widget plugin.
If you can see your widget in designer, your plugin is working the way you've specified it to. Your problem is basically that the program you're compiling can't find the header file for the widget you are adding via the plugin. The answer is likely one of two things:
- Add more of the path to the header in your plugin, so that programs which use the widget can find the header appropriately.
- Add the path to the header file as an include path to your compiler, so the compiler can find the appropriate header when the program's files reference it.
I faced with same issue. Then i tried to add all header files and .cpp files of plugin DLL into applications project file explicitly.it fixed the issue.