qml - How to show a window?
-
There is this book about qml http://qmlbook.github.io/en/ch02/index.html
and when I tried to run this example in qt creator or as ./project_name where project_name is executable file created by qt creator there is no visible window:Rectangle { width: 360 height: 360 Text { anchors.centerIn: parent text: "Hello World" } MouseArea { anchors.fill: parent onClicked: { Qt.quit(); } } } why is that? Am I missing soething or maybe I have chosen wrong project type (Qt Quick Application - Empty)? The only way to see the window is to run: **qmlscene main.qml**
-
@twar said in qml - How to show a window?:
when I tried to run this example in qt creator or as ./project_name where project_name is executable file created by qt creator there is no visible window:
...
why is that?
...
The only way to see the window is to run:
qmlscene main.qmlYou used a
Rectangle
as your application's top-level object. However, aRectangle
needs to be put in an actual window to be seen. To create a window for this file, on the C++ side you must to load your QML file in aQQuickView
orQQuickWidget
. This is the old way of displaying a QML-based GUI.Note: qmlscene contains a
QQuickView
that dynamically loads the QML file that you specify.The new way does not require
QQuickView
orQQuickWidget
; instead, it lets you define a window directly in QML code. To see it in action, just create a new Qt Quick Application (it doesn't matter which type) and look at the auto-generated code. You'll see that it has aWindow
at the top-level, not aRectangle
.EDIT: The auto-generated code is complete. You can run it.
There is this book about qml http://qmlbook.github.io/en/ch02/index.html
...
Am I missing soething or maybe I have chosen wrong project type (Qt Quick Application - Empty)?That tutorial was written before it was possible to create a
Window
in QML code. -
@JKSH Im following the beginner tutorial and it says to replace the Window object with a Rectangle object to set state, yet when I do that, no graphic is fired when the app is ran. Any idea how I can set the state on a window object or get the rectangle object to show up?
-
@streetcoder said in qml - How to show a window?:
Im following the beginner tutorial and it says to replace the Window object with a Rectangle object to set state, yet when I do that, no graphic is fired when the app is ran. Any idea how I can set the state on a window object or get the rectangle object to show up?
I'm not sure which tutorial you mean. Can you please post your code?
(Also, in the future please open a new thread for new questions)