3

I recently installed the Qt5 RC2 for Mac OS X and started developing some QML applications. After looking at the new elements, I especially wanted to try the Window and Screen Element. (http://qt-project.org/doc/qt-5.0/qtquick/qmlmodule-qtquick-window2-qtquick-window-2.html)

So I set the imports at the top of the file like this:

import QtQuick 2.0
import QtQuick.Window 2.0

The import is found, but I can use neither Window nor Screen. Everytime I type Screen or Window an error appears which says "Unknown component (M300)"

Has anyone an idea what the problem is?

Dominik
  • 98
  • 1
  • 7

1 Answers1

5

Sometimes QtCreator doesn't recognize some types/properties, mainly the ones that were not present in Qt4.x, but that doesn't mean you can't use them, so yes, 'Window' is unknown just like properties 'antialiasing', 'fontSizeMode' or 'active' are, but you can use them, here is an example of use for QtQuick.Window 2.0 :

import QtQuick        2.0
import QtQuick.Window 2.0

Window {
    id: win1;
    width: 320;
    height: 240;
    visible: true;
    color: "yellow";
    title: "First Window";

    Text {
        anchors.centerIn: parent;
        text: "First Window";

        Text {
            id: statusText;
            text: "second window is " + (win2.visible ? "visible" : "invisible");
            anchors.top: parent.bottom;
            anchors.horizontalCenter: parent.horizontalCenter;
        }
    }
    MouseArea {
        anchors.fill: parent;
        onClicked: { win2.visible = !win2.visible; }
    }

    Window {
        id: win2;
        width: win1.width;
        height: win1.height;
        x: win1.x + win1.width;
        y: win1.y;
        color: "green";
        title: "Second Window";

        Rectangle {
            anchors.fill: parent
            anchors.margins: 10

            Text {
                anchors.centerIn: parent
                text: "Second Window"
            }
        }
    }
}

You just need to have a Window item as root object, and you can embed other Window items into it.

TheBootroo
  • 7,408
  • 2
  • 31
  • 43