Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Load QML Plugins through QDeclarativeEngine
Forum Updated to NodeBB v4.3 + New Features

Load QML Plugins through QDeclarativeEngine

Scheduled Pinned Locked Moved QML and Qt Quick
7 Posts 2 Posters 4.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    aliander
    wrote on last edited by
    #1

    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!
    Ali

    1 Reply Last reply
    0
    • B Offline
      B Offline
      bunjee
      wrote on last edited by
      #2

      What is MyPushButton ?

      1 Reply Last reply
      0
      • A Offline
        A Offline
        aliander
        wrote on last edited by
        #3

        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":http://doc.troll.no/master-snapshot/declarative-cppextensions-qwidgets.html

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

        1 Reply Last reply
        0
        • B Offline
          B Offline
          bunjee
          wrote on last edited by
          #4

          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 ?

          1 Reply Last reply
          0
          • A Offline
            A Offline
            aliander
            wrote on last edited by
            #5

            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. (qwidgets.pro/.qml/.cpp 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 ;)

            1 Reply Last reply
            0
            • B Offline
              B Offline
              bunjee
              wrote on last edited by
              #6

              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");@

              1 Reply Last reply
              0
              • A Offline
                A Offline
                aliander
                wrote on last edited by
                #7

                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 ;)

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved