QQmlApplicationEngine failed to load component qrc:/main.qml: Invalid attached object assignment



  • Given my thoughts below am I barking up the wrong tree? Or provided the information below am I misusing the API to get the error in the title?

    I am trying to modify the sample at http://doc.qt.io/qt-5/qtquick-scenegraph-openglunderqml-example.html to work with the default QtQuick project generated with Qt Creator 3.3.0 (opensource)
    Based on Qt 5.4.0 (GCC 4.6.1, 64 bit).

    After looking through the code the first thing that stands out to me is:

    The samples main.cpp uses:
    @
    qmlRegisterType<Squircle>("OpenGLUnderQML", 1, 0, "Squircle");

    QQuickView view;
    view.setResizeMode(QQuickView::SizeRootObjectToView);
    view.setSource(QUrl("qrc:///scenegraph/openglunderqml/main.qml"));
    view.show();
    

    @

    With some renaming my main.cpp uses

    @
    qmlRegisterType<MainScreen>("OpenGLUnderQML", 1, 0, "MainScreen");

    QQmlApplicationEngine engine;
    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    

    @

    I am not sure if the difference in using a QQmlApplicationEngine over a QuickView could be causing my error:

    @
    QQmlApplicationEngine failed to load component
    qrc:/main.qml:23 Invalid attached object assignment
    @

    Where my main.qml looks like:

    @
    import QtQuick 2.4
    import QtQuick.Window 2.2
    import OpenGLUnderQML 1.0

    import "qmlmodel"

    Window {
    id: mainWindow
    width: 800
    height: 600
    visible: true
    color: "black"
    title: "Army Calculator"
    objectName: "mainWindow"

    ListView {
        id: mainListView
        anchors.fill: parent
        objectName: "mainListView"
    }
    
    MainScreen {
        SequentialAnimation on DeltaT {
            NumberAnimation { to: 1; duration: 2500; easing.type: Easing.InQuad }
            NumberAnimation { to: 0; duration: 2500; easing.type: Easing.OutQuad }
            loops: Animation.Infinite
            running: true
        }
    }
    

    }
    @

    and the sample uses:

    @
    import QtQuick 2.0
    import OpenGLUnderQML 1.0

    Item {

    width: 320
    height: 480
    
    Squircle {
        SequentialAnimation on t {
            NumberAnimation { to: 1; duration: 2500; easing.type: Easing.InQuad }
            NumberAnimation { to: 0; duration: 2500; easing.type: Easing.OutQuad }
            loops: Animation.Infinite
            running: true
        }
    }
    Rectangle {
        color: Qt.rgba(1, 1, 1, 0.7)
        radius: 10
        border.width: 1
        border.color: "white"
        anchors.fill: label
        anchors.margins: -10
    }
    
    Text {
        id: label
        color: "black"
        wrapMode: Text.WordWrap
        text: "The background here is a squircle rendered with raw OpenGL using the 'beforeRender()' signal in QQuickWindow. This text label and its border is rendered using QML"
        anchors.right: parent.right
        anchors.left: parent.left
        anchors.bottom: parent.bottom
        anchors.margins: 20
    }
    

    }@


  • Moderators

    Hi,

    Have you renamed the Squircle class to MainScreen ?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.