Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. qml - How to show a window?
Forum Updated to NodeBB v4.3 + New Features

qml - How to show a window?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 3 Posters 949 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    twar
    wrote on last edited by
    #1

    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**
    
    JKSHJ 1 Reply Last reply
    0
    • T twar

      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**
      
      JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by JKSH
      #2

      @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.qml

      You used a Rectangle as your application's top-level object. However, a Rectangle 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 a QQuickView or QQuickWidget. 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 or QQuickWidget; 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 a Window at the top-level, not a Rectangle.

      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.

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      S 1 Reply Last reply
      5
      • JKSHJ JKSH

        @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.qml

        You used a Rectangle as your application's top-level object. However, a Rectangle 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 a QQuickView or QQuickWidget. 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 or QQuickWidget; 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 a Window at the top-level, not a Rectangle.

        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.

        S Offline
        S Offline
        streetcoder
        wrote on last edited by
        #3

        @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?

        JKSHJ 1 Reply Last reply
        0
        • S streetcoder

          @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?

          JKSHJ Offline
          JKSHJ Offline
          JKSH
          Moderators
          wrote on last edited by
          #4

          @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)

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved