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. Rectangle as a root error in QtQuick project
Forum Updated to NodeBB v4.3 + New Features

Rectangle as a root error in QtQuick project

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 2 Posters 1.7k Views 1 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.
  • freddy311082F Offline
    freddy311082F Offline
    freddy311082
    wrote on last edited by
    #1

    Hi guys

    I'm after update to 5.3 version, I have some troubles creating QtQuick projects... With 5.2.1 version when I set a Rectangle as a root of my project, had no problem... Now, when I create a QtQuick project, QtCreator generate a main.qml as we all know, and the root object is Window.

    if I change Window by Rectangle, the application doesn't show... here is the code:

    This is the coge generated by qtcreator:

    @import QtQuick 2.2

    Window {
    visible: true
    width: 360
    height: 360

    MouseArea {
        anchors.fill: parent
        onClicked: {
            Qt.quit();
        }
    }
    
    Text {
        text: qsTr("Hello World")
        anchors.centerIn: parent
    }
    

    }
    @

    This is what it doesn't work

    @import QtQuick 2.2

    Rectangle {
    visible: true
    width: 360
    height: 360

    MouseArea {
        anchors.fill: parent
        onClicked: {
            Qt.quit();
        }
    }
    
    Text {
        text: qsTr("Hello World")
        anchors.centerIn: parent
    }
    

    }
    @

    I'm using OS X 10.9.3

    regards

    Freddy

    1 Reply Last reply
    0
    • JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      Hi,

      If you change main.qml, you also need to change main.cpp

      @
      // Change this...
      QQmlApplicationEngine engine;
      engine.load(QUrl(QStringLiteral("qrc:///main.qml")));

      // ...to this:
      QQuickView view(QUrl(QStringLiteral("qrc:///main.qml")));
      view.show();
      @

      QQmlApplicationEngine takes Window. QQuickView takes Rectangle.

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

      1 Reply Last reply
      0
      • freddy311082F Offline
        freddy311082F Offline
        freddy311082
        wrote on last edited by
        #3

        Thanks JSKH, for your reply...

        and when is it better use QQmlApplicationEngine and QQuickView ??

        regards

        1 Reply Last reply
        0
        • JKSHJ Offline
          JKSHJ Offline
          JKSH
          Moderators
          wrote on last edited by
          #4

          You're welcome :)

          [quote author="freddy311082" date="1401503871"]when is it better use QQmlApplicationEngine and QQuickView ??[/quote]If you want a top-level QML window that has a menubar, statusbar and/or toolbar, then you should use QQmlApplicationEngine (with "ApplicationWindow":http://qt-project.org/doc/qt-5/qml-qtquick-controls-applicationwindow.html as your root).

          If you want to embed a QML GUI inside a widget GUI, you should use QQuickView (Qt 5.0 -- Qt 5.2) or QQuickWidget (Qt 5.3 and later).

          But if you don't need either of these, then it doesn't really matter which one you choose.

          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