⚠️ Forum Maintenance: Feb 6th, 8am - 14pm (UTC+2)

Access class returned by QGenericPlugin::create

  • Hi All,

    I am just getting familiar with the Qt plugin architecture. Currently I am checking out the tuiotouch plugin, which receives UDP packets and parses out tuio protocol messages to forward tracked data into the applictaion as touch events. I was able to get it all up and running, but I was wondering if it is possible to access the data maintained by the plugin itself.

    I looked into the plugin source and noticed that the QTuioTouchPlugin returns a QTuioHandler when QTuioTouchPlugin::create(...) is called. Here is the code copied from C:\Qt\5.8\Src\qtbase\src\plugins\generic\tuiotouch\main.cpp:

    #include <QtGui/qgenericplugin.h>
    #include <QCoreApplication>
    #include "qtuiohandler_p.h"
    class QTuioTouchPlugin : public QGenericPlugin
        Q_PLUGIN_METADATA(IID QGenericPluginFactoryInterface_iid FILE "tuiotouch.json")
        QObject* create(const QString &key, const QString &specification);
    QObject* QTuioTouchPlugin::create(const QString &key,
                                             const QString &spec)
        if (!key.compare(QLatin1String("TuioTouch"), Qt::CaseInsensitive))
            return new QTuioHandler(spec);
        return 0;

    Using the QPluginLoader class I am loading the tuiotouch dll and then instaciate a QGenericPlugin from it:

    QPluginLoader loader("path/to/dll");
    QObject *plugin_obj = loader.instance();
    auto plugin = qobject_cast<QGenericPlugin*>(plugin_obj);

    I then proceed to create the plugin using the interface described from the plugin source main (see above):

    QObject* plugin_handle = plugin->create("TuioTouch",  "udp=3333");

    I want to access the class interface of QTuioHandler. Can I somehow make my compiler familiar with this QObject subclass returned by create? Can I somehow create a class header for QTuioHandler, so I can cast auto plugin_tuio_handle = qobject_cast<QTuioHandler*>(plugin_handle)?

    The plugin is compiled as a dll, so I am realizing that what I am asking might be a bit difficult to say the least.

  • Lifetime Qt Champion


    Do you mean the qtuiohandler_p.h header file ?

    Out of curiosity, why do you want to do that?

Log in to reply