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. [SOLVED] Rectangle as root element in .qml file
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Rectangle as root element in .qml file

Scheduled Pinned Locked Moved QML and Qt Quick
qmlqt quick 2.4qt quick
3 Posts 2 Posters 2.3k 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.
  • F Offline
    F Offline
    fatinbrain
    wrote on 4 Sept 2015, 07:18 last edited by fatinbrain 9 Apr 2015, 10:46
    #1

    I use Qt 5.5.0 MSVC 2013, 32bit.
    I want to create minimal QtQuick application. When I choose New Project - Qt Quick Application I got project with 2 QML files: main.qml and MainForm.ui.qml. Since I do not need them, I delete second one and paste following to main.qml:

    Import QtQuick 2.4
    
    Rectangle{
        id: root
        visible: true
        color: "gray"
        width: 400
        height: 800
    }
    

    But when I run project I got nothing. I see application in Task Manager but there is no application window.
    Question: Is it possible to create .qml file with Rectangle as a root element?

    P 1 Reply Last reply 4 Sept 2015, 07:38
    0
    • F fatinbrain
      4 Sept 2015, 07:18

      I use Qt 5.5.0 MSVC 2013, 32bit.
      I want to create minimal QtQuick application. When I choose New Project - Qt Quick Application I got project with 2 QML files: main.qml and MainForm.ui.qml. Since I do not need them, I delete second one and paste following to main.qml:

      Import QtQuick 2.4
      
      Rectangle{
          id: root
          visible: true
          color: "gray"
          width: 400
          height: 800
      }
      

      But when I run project I got nothing. I see application in Task Manager but there is no application window.
      Question: Is it possible to create .qml file with Rectangle as a root element?

      P Offline
      P Offline
      p3c0
      Moderators
      wrote on 4 Sept 2015, 07:38 last edited by
      #2

      @fatinbrain The template for creating Qt Quick Application adds QQmlApplicationEngine to launch the QML. But QQmlApplicationEngine dont work directly with Rectangle or Item as root element but requires any window like Window or ApplicationWindow.
      So to make it work for Rectangle use QQuickView instead of QQmlApplicationEngine.

      157

      1 Reply Last reply
      5
      • F Offline
        F Offline
        fatinbrain
        wrote on 4 Sept 2015, 10:52 last edited by
        #3

        @p3c0 Checkmate! Thanks.

        1 Reply Last reply
        0

        1/3

        4 Sept 2015, 07:18

        • Login

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