Nominate our 2022 Qt Champions!

Pie Menu Simple Example

  • Hi,

    can someone please help me fix this error message:

    Starte C:\Users\Rick\Documents\build-Custom-Desktop_Qt_5_10_0_MSVC2017_64bit-Debug\debug\Custom.exe...
    QML debugging is enabled. Only use this in a safe environment.
    QQmlApplicationEngine failed to load component
    qrc:/main.qml:15 Cannot assign object to list property "menuItems"


    import QtQuick 2.9
    import QtQuick.Controls 2.2
    import QtQuick.Window 2.2
    import QtQuick.Extras 1.4
    Window {
        visible: true
        width: 640
        height: 480
        title: qsTr("Hello World")
        PieMenu {
            id: pieMenu
            MenuItem {
                text: "Action 1"
                onTriggered: print("Action 1")
            MenuItem {
                text: "Action 2"
                onTriggered: print("Action 2")
            MenuItem {
                text: "Action 3"
                onTriggered: print("Action 3")

    Examle from:

    # depend on your compiler). Please consult the documentation of the
    # deprecated API in order to know how to port your code away from it.
    # You can also make your code fail to compile if you use deprecated APIs.
    # In order to do so, uncomment the following line.
    # You can also select to disable deprecated APIs only up to a certain version of Qt.
    #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
    SOURCES += \
    RESOURCES += qml.qrc
    # Additional import path used to resolve QML modules in Qt Creator's code model
    # Additional import path used to resolve QML modules just for Qt Quick Designer
    # Default rules for deployment.
    qnx: target.path = /tmp/$${TARGET}/bin
    else: unix:!android: target.path = /opt/$${TARGET}/bin
    !isEmpty(target.path): INSTALLS += target


    #include <QGuiApplication>
    #include <QQmlApplicationEngine>
    int main(int argc, char *argv[])
        QGuiApplication app(argc, argv);
        QQmlApplicationEngine engine;
        if (engine.rootObjects().isEmpty())
            return -1;
        return app.exec();

    After 2 hours I still couldn't fix it although it is a simple example.

    System: Windows 10 x64, MSVC2017, Qt 5.10.0

    Thank you all and sorry for this beginner question.



    PS: I also tried QML lists ([MenuItem{...}, MenuItem{...}]) and repeaters. Same error message.

  • The problem is that MenuItem is member of QtQuick.Controls 1.* module and you are importing QtQuick.control 2.2.

    The below code solve your problem:

    import QtQuick 2.9
    //import QtQuick.Controls 2.2
    import QtQuick.Controls 1.4
    import QtQuick.Window 2.2
    import QtQuick.Extras 1.4

Log in to reply