1

Let’s say that we have a very simple QML file, like this one:

import QtQuick 2.0

Rectangle {
    width: 800
    height: 600
    color: '#000'

    Text {
        text: qsTr("Hi all")
        anchors.centerIn: parent
    }
}

The QML File is loaded with the QtQuick2ApplicationViewer helper class, like this:

QtQuick2ApplicationViewer viewer;
viewer.setMainQmlFile(QStringLiteral("qml/MyApp/Login/Window.qml"));
viewer.showFullScreen();

How should I proceed, if for example I would like to change the Rectangle’s color to white, from C++. My guess was:

QQuickItem *window = viewer.rootObject();
window->setProperty("color", "#fff");

But all that does is the following compiler error:

invalid use of incomplete type 'struct QQuickItem'
forward declaration of 'struct QQuickItem'
2
  • 4
    Did you include QQuickItem? Commented Dec 2, 2012 at 12:20
  • 2
    @LucaCarlon :D Thanks a lot. Never could have thought of it. Commented Dec 2, 2012 at 12:29

2 Answers 2

6

Then QQuickItem was forward declared somewhere in a header you included, but not fully qualified. Here more information.

Sign up to request clarification or add additional context in comments.

Comments

2
QObject *rootObject = (QObject *)viewer.rootObject();
rootObject->setProperty("color", "red");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.