Uploaded image for project: 'Qt Creator'
  1. Qt Creator
  2. QTCREATORBUG-11264

Update & Simplify Qt Quick Application wizards

    XMLWordPrintable

Details

    • 848a725e3b3bd51394ddbd0a10be52a8ae0bdd25

    Description

      Although the Qt Quick application wizard underwent a 'renovation' in 3.0 the structure & content of the generated files itself where only adapted somewhat. After some discussion the consensus seems to be that we should aim for

      • Getting rid of the file by file deployment, and use qrc:// instead.
      • Getting rid of the automatically generated glue code

      QRC This is the most 'universal' way of deployment, and allows us to get rid of the 100 lines monster that is deployment.pri. qmlapplicationviewer.[h|cpp] and friends were hacks to allow us hiding the differences between OS versions. Using qrc:// gets rid of the problem to find the 'right' folder on the target os, while QQmlApplicationEngine (new in Qt 5.1) handles other glue code .

      To get this, we should change the template for Qt Quick Controls, Qt Quick 2.0:

      Qt Quick 2.1 wizard

      Bump requirement to Qt 5.1.0 or newer

      main.pro:

      TEMPLATE = app
      
      QT += qml quick
      
      SOURCES += main.cpp
      
      RESOURCES += qml.qrc
      
      # Additional import path used to resolve QML modules in Qt Creator's code model
      QML_IMPORT_PATH =
      

      main.cpp:

      #include <QtGui/QGuiApplication>
      #include <QtQml/QQmlApplicationEngine>
      
      int main(int argc, char *argv[])
      {
          QGuiApplication app(argc, argv);
      
          QQmlApplicationEngine engine;
          engine.load(QUrl(QStringLiteral("qrc:///qml/main.qml")));
      
          return app.exec();
      }
      

      qml.qrc:

      <RCC>
          <qresource prefix="/">
              <file>qml/main.qml</file>
          </qresource>
      </RCC>
      

      qml/main.qml:

      import QtQuick 2.1
      import QtQuick.Window 2.1
      
      Window {
          visible: true
          width: 360
          height: 360
      
          Text {
              text: qsTr("Hello World")
              anchors.centerIn: parent
          }
      
          MouseArea {
              anchors.fill: parent
              onClicked: {
                  Qt.quit();
              }
          }
      }
      

      Qt Quick Controls 1.0 wizard:

      main.pro:

      TEMPLATE = app
      
      QT += qml quick widgets
      
      SOURCES += main.cpp
      
      RESOURCES += qml.qrc
      
      # Additional import path used to resolve QML modules in Qt Creator's code model
      QML_IMPORT_PATH =
      

      main.cpp:

      #include <QtQml/QQmlApplicationEngine>
      #include <QtWidgets/QApplication>
      
      int main(int argc, char *argv[])
      {
          QApplication app(argc, argv);
      
          QQmlApplicationEngine engine;
          engine.load(QUrl(QStringLiteral("qrc:///qml/main.qml")));
      
          return app.exec();
      }
      

      qml.qrc:

      <RCC>
          <qresource prefix="/">
              <file>qml/main.qml</file>
          </qresource>
      </RCC>
      

      qml/main.qml:

      import QtQuick 2.1
      import QtQuick.Controls 1.0
      
      ApplicationWindow {
          visible: true
          width: 640
          height: 480
          title: qsTr("Hello World")
      
          menuBar: MenuBar {
              Menu {
                  title: qsTr("File")
                  MenuItem {
                      text: qsTr("Exit")
                      onTriggered: Qt.quit();
                  }
              }
          }
      
          Text {
              text: qsTr("Hello World")
              anchors.centerIn: parent
          }
      }
      

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              jkobus Jarek Kobus
              kkohne Kai Köhne
              Votes:
              2 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes