Important: Please read the Qt Code of Conduct -

[Partially Solved] QML & qmlRegisterType

  • Hi there,

    i'm a bit confused with qml type registering and QObject-derived objects.

    In my case, i would like to use QToolBox in my QML GUI.

    EDIT : My bad, QToolBox is a QWidget-derived object...

    How am i supposed to do this ?

    I tried a basic :

    @ qmlRegisterType<QToolBox>("MyQMLObjects.MyToolBox", 1, 0, "QToolBox");@

    in my main.cpp before importing in my main.qml :

    @import MyQMLObjects.MyToolBox 1.0;@

    And here it asks me plenty of weird message i usually had when i have MOC Problems. (You see, it's kinda "_Qfbksdqbgflsdfjqùm21 not found in moc_dummy.cpp at line 42.")

    So, my question is : Can i expose QtWidgets such as QToolBox, QMenu... in QML ?

  • You can't quite do it like this, particularly if you want to use the widgets as items in QML.

    Google 'QML embed QWidget' and you can see examples for how to do this with QGraphicsProxyWidget.
    That is a solution that only works for QtQuick 1.1. For QtQuick 2.0 I don't know if/how that could be achieved.

    QGraphicsProxyWidget example is "here":

  • Thanks for the reply.

    And yeah, i found QGraphicsProxyWidget and was trying to find the QtQuick2.0 way of doing quite the same thing.

    Obviously, the straightest way would be to code the plugin I needed. Just as the qml-QPushButton which is described in Qt examples. If it's no longer possible or recommanded in QtQuick2.0 to use QGraphicsProxyWidget, I guess the solution is here to recode what i need in a QML plugin.

    If someone has a clue about the QtQuick2.0 way of doing this, It could be great.

  • So, i had a look around and what i've found i mostly "wait 5.1".

    If someone has another clue, i would be grateful. If not, i'll wait for 5.1.

  • So, in new qt qiuck2 .0from qt 5.1 i can use qmlRegisterType or not? Can't find information about it. :{


Log in to reply