Important: Please read the Qt Code of Conduct -

Load QML Plugins through QDeclarativeEngine

  • Hi there!

    I currently try to get the QWidgets (in the CppExtensions-Examples) running.

    Having the standard example code and trying to load the qml through QDeclarativeEngine gives me the error, that MyPushButton is not a type.

    What am I missing?

    As those plugins are intended to dynamically extend QML, I'm pretty sure, that I don't have to register the type in my core-application (just providing a kind of self-written qmlviewer). Later on the core-application should do some system related stuff aswell, so using the qmlviewer itself won't help :(

    Thanks in advance!

  • What is MyPushButton ?

  • MyPushButton is just a simple QPushButton wich should be provided to qml with a plugin
    It is implemented in the examples (declarative/cppextensions/qwidgets)

    Here you go: "Link":

    For this discussion I have chosen a provided example on purpose - so we have the same discussion base ;)

  • Do you have this in your cpp:
    @qmlRegisterType<MyPushButton>(uri, 1, 0, "MyPushButton");@

    And this in your qml:
    @import "QWidgets" 1.0@

    Does the qwidgets example works for you ?

  • Having
    @import "QWidgets" 1.0@
    in my test qml File (qwidgets.qml)

    I don't intend to register the MyPushButton Type in my cpp core-application. The qmlRegisterType should be done through the QWidgetsPlugin (derived from QDeclarativeExtensionPlugin).

    I use the example as it is - absolutely no modification. ( and qmldir used from example)

    The point is, that I can't use the qmlviewer to load it, but have to use my own application using a QDeclarativeEngine

    The Code is kinda straight forward:

    @#include <QtDeclarative>

    #include <QCoreApplication>

    #include <QDeclarativeEngine>

    #include <QDeclarativeContext>

    #include <QDeclarativeComponent>

    #include <QDebug>

    int main(int argc, char *argv[])


    QCoreApplication app(argc, argv);
    QDeclarativeEngine engine;
    QDeclarativeContext *context = new QDeclarativeContext(engine.rootContext());
    QDeclarativeComponent component(&engine, "qwidgets.qml");
    QObject *window = component.create(context);
    qDebug() << component.errors();
    return app.exec&#40;&#41;;


    As I understand QML plugins are supposed to work that way... else ... well, that would be pretty sad ;)

  • Well I guess he is not loading your plugin.

    In your code. Can you try putting a qDebug before:

    @qmlRegisterType<MyPushButton>(uri, 1, 0, "MyPushButton");@

  • Currently doing a fresh rebuild now...

    Surprisingly I get a new error msg now

    @QWidget: Cannot create a QWidget when no GUI is being used@

    So hooray, the plugin-loading seems not to be the problem...for the moment ;)

Log in to reply