I have problems building an application that uses a Qt Designer plugin on Windows. Can you give some advice?

First of all, you need to export your class so that it can be used by the
plugin, e.g:

  1. class QDESIGNER_WIDGET_EXPORT button : public QPushButton

Also, make sure you have the Q_OBJECT macro in your class declaration, if you
do not include it then the plugin will not have access to the correct
QMetaObject which would have information about the class itself. As a result
this would break the introspection of the plugin.

In the .pro file of your plugin you also need to give some extra information

  1. TEMPLATE = lib

Make sure you specify the lib template since you are building a library.

  1. DESTDIR = $$[QT_INSTALL_PLUGINS]/designer

In addition you need to specify where the plugin should be located. Qt will
look in plugins/designer by default, so this is where your plugin should be.

An example .pro file may like look this:

  1. TEMPLATE = lib
  2. CONFIG+= designer plugin debug_and_release
  3. LANGUAGE = C++
  4. TARGET = buttonPlugin
  5. SOURCES += buttonPlugin.cpp button.cpp
  6. HEADERS += buttonPlugin.h button.h
  7. DESTDIR = $$[QT_INSTALL_PLUGINS]/designer
  8. CONFIG += qt warn_on release plugin

With your application you need to add the following to your application’s .pro
file:

  1. LIBS+=$$[QT_INSTALL_PLUGINS]/designer/nameOfYourPlugin.lib

This line is necessary to link against the lib file and at runtime the
application will use the dll. The lib file is located at
$$[QT_INSTALL_PLUGINS]/designer since this is what was specified as the
DESTDIR in the plugin’s pro file.

  1. INCLUDEPATH += text/example/yourPluginDir/yourWidget

You also need to specify the INCLUDEPATH, so that your application will be
able to find your custom widget’s header file.

An example .pro file can look as follows:

  1. TEMPLATE = app
  2. LANGUAGE = C++
  3. LIBS += $$[QT_INSTALL_PLUGINS]/designer/buttonPlugin.lib
  4. INCLUDEPATH += text/example/yourPluginDir/yourWidget
  5. CONFIG += qt warn_on release
  6. SOURCES += main.cpp
  7. FORMS = form1.ui

Finally, your application also needs to be able to find the plugin’s dll. This
can be done either by putting the myPlugin.dll into the same directory as your
application, or by adding the path to the myPlugin.dll to the PATH environment
variable.

No comments

Write a comment

Sorry, you must be logged in to post a comment.