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") {
            pluginsDir.cdUp();
            pluginsDir.cdUp();
            pluginsDir.cdUp();
            pluginsDir.cdUp();
            pluginsDir.cdUp();
        }
        pluginsDir.cd("plugins");
        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

    Hi,

    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:

    QT_DEBUG_PLUGINS

    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 += \
        reactionfileform.ui
    
    DISTFILES += \
        reactionsserver.plugin.json
    

    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_OBJECT
        Q_PLUGIN_METADATA( IID "org.qt-project.Qt.AddHaptics.ReactionsServerInterface" FILE "reactionsserver.plugin.json" )
        Q_INTERFACES(ReactionsServerInterface)
    
    public:
        ReactionsServerPlugin( CreatorWindow* parent ) { setParent( parent ); } // makes this qwidget a child window
    
        void createForm();  // override;
        void showForm();    // override
        void hideForm();
    
    private:
        Ui::ReactionServerFileForm* ui;
    
    };
    
    #endif // REACTIONSSERVER_GLOBAL_H
    

    Below is my source:

    #include <QtWidgets>
    
    #include "reactionsserverplugin.h"
    #include "ui_reactionfileform.h"
    
    void ReactionsServerPlugin::createForm()
    {
        ui = new Ui::ReactionServerFileForm;
        ui->setupUi(this);
    }
    
    void ReactionsServerPlugin::showForm() {
        this->setVisible(true);
    }
    
    void ReactionsServerPlugin::hideForm() {
        this->setVisible(false);
    }
    

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


  • Qt Champions 2016

    Hi
    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

    #ifndef REACTIONSSERVER_INTERFACE_H
    #define REACTIONSSERVER_INTERFACE_H
    
    class ReactionsServerInterface
    {
    
    public:
        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)
    
    #endif // REACTIONSSERVER_H
    
    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.


  • Qt Champions 2016

    @mgreenish
    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
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.