Loading my first newly built plugin while debugging

  • I expect this is a simple problem but I'm stuck loading my new plugin. I am developing on OS X.

    I have written a plugin to dynamically extend functionality in my application, following the EchoWindowPlugin example provided by QT. The application compiles and the plugin compiles. However, my application does not seem to load the plugin.

    I am loading, as per the example, as follows below:

    bool CreatorWindow::loadReactionServerPlugin()
    QDir pluginsDir(qApp->applicationDirPath());
    if (pluginsDir.dirName() == "MacOS") {
        qDebug() << "Plugins dir " + pluginsDir.absolutePath();
        foreach (QString fileName, pluginsDir.entryList(QDir::Files)) {
            QPluginLoader pluginLoader(pluginsDir.absoluteFilePath(fileName));
            QObject *plugin = pluginLoader.instance();
            if( plugin ) {
                reactionsserverInterface = qobject_cast<ReactionsServerInterface *>(plugin);
                if( reactionsserverInterface ) {
                    return true;
        return false;

    Both are compiled in debug mode.

    I have checked and I am looking in the correct directory and the pluginLoader constructor gets passed my plugin ReactionServerPlugin_debug.dylib but the 'plugin' QObject pointer is still null. What am I missing?

  • Lifetime Qt Champion


    You should set the QT_DEBUG_PLUGINS environnement variable to 1 and re-run your application. You’ll get more information about what is happening.

  • @SGaist said in Loading my first newly built plugin while debugging:


    Great! Now I get a message in the Application Output:

    QMachOParser: '/Users/greanie/Work/HapticX/Engineering/Software/plugins/libreactionsserverplugin_debug.dylib' is not a Qt plugin

    So somehow my plugin is not properly set up.

    Below is my .pro file:

    TEMPLATE        = lib                                       # making a library, not an executible
    CONFIG         += plugin                                    #
    QT             += widgets network gui
    INCLUDEPATH    += ../vibecreator/vibecreator/               # include path to plugin interface
    TARGET          = $$qtLibraryTarget(reactionsserverplugin)  # name of the library file in which the plugin will be stored, should be same as name of the plugin
    DESTDIR         = ../plugins
    # install
    target.path = ../plugins
    INSTALLS += target
    CONFIG += install_ok  # Do not cargo-cult this!
    SOURCES += reactionsserverplugin.cpp
    HEADERS  += reactionsserverplugin.h
    FORMS += \
    DISTFILES += \

    Below is my plugin header:

    #include <QObject>
    #include <QWidget>
    #include <QtPlugin>
    #include <QDialog>
    //#include "../vibecreator/vibecreator/reactionsserverinterface.h"
    #include "reactionsserverinterface.h"
    #include "creatorwindow.h"
    namespace Ui {
        class ReactionServerFileForm;
    class ReactionsServerPlugin : public QWidget, ReactionsServerInterface
        Q_PLUGIN_METADATA( IID "org.qt-project.Qt.AddHaptics.ReactionsServerInterface" FILE "reactionsserver.plugin.json" )
        ReactionsServerPlugin( CreatorWindow* parent ) { setParent( parent ); } // makes this qwidget a child window
        void createForm();  // override;
        void showForm();    // override
        void hideForm();
        Ui::ReactionServerFileForm* ui;

    Below is my source:

    #include <QtWidgets>
    #include "reactionsserverplugin.h"
    #include "ui_reactionfileform.h"
    void ReactionsServerPlugin::createForm()
        ui = new Ui::ReactionServerFileForm;
    void ReactionsServerPlugin::showForm() {
    void ReactionsServerPlugin::hideForm() {

    It all compiles, as per the dylib file. Any ideas on what I might be doing wrong?

  • Lifetime Qt Champion

    For the ReactionsServerInterface
    Do you have something like
    Q_DECLARE_INTERFACE(ReactionsServerInterface, "in.forwardbias.tool/1.0")
    under the class definition ?

  • @mrjj I didn't put my interface class in my past post because I figured my problem was a set up one with the plugin. But, here it is

    class ReactionsServerInterface
        virtual ~ReactionsServerInterface(){}
        virtual void createForm() = 0;
        virtual void showForm() = 0;
        virtual void hideForm() = 0;
    #define ReactinonsSeverInterface_iid "org.qt-project.Qt.AddHaptics.ReactionsServerInterface"
    Q_DECLARE_INTERFACE(ReactionsServerInterface, ReactinonsSeverInterface_iid)
    I do have the Q_DECLARE_INTERFACE .

    The only thing I can find that is wrong in my plugin is that I get a warning that reactionsserver.plugin.json doesn't hold a valid json object. But I don't know how that would influence whether or not my plugin is a valid plugin.

  • Lifetime Qt Champion

    I also got that message as far as i can recall but it still loaded.

  • Lifetime Qt Champion

    Can you show the json ?

  • I read in a post that it could be left blank, so that gave me an error that cased the compiler to error out. So I found this online and now I only get a warning:

    @{ "Keys": [ "reactionserveristhisplugin" ] }@

    Granted, I haven't figured out what is wrong with this structure as I didn't think this would be source of my error.

    The warning is:

    ../reactionsserverplugin.h:20: Warning: Plugin Metadata file "reactionsserver.plugin.json" does not contain a valid JSON object. Declaration will be ignored

  • Lifetime Qt Champion

    Might be silly but I wonder if it's because you have two dots in your file name.

  • That doesn't seem to be it:

    ../reactionsserverplugin.h:20: Warning: Plugin Metadata file "reactionsserverplugin.json" does not contain a valid JSON object. Declaration will be ignored

  • Lifetime Qt Champion

    Again might be silly but did you try to lint your json file ? Might have a stray char somewhere that's messing things up.

        "Keys": ["reactionserveristhisplugin"]

    Should be good.

  • @SGaist So it turns out that this file is optional. I removed it from the Q_PLUGIN_METADATA declaration and that seemed to resolve the warning. Now everything compiles and the dylib loads.

Log in to reply