When you create a new Qt Quick project from scratch, you have the following options:
Qt Quick UI projects cannot be deployed to embedded or mobile target platforms. For those platforms, create a Qt Quick application instead.
注意: The SDK for a particular target platform might install additional templates for that platform. For example, the QNX templates are installed as part of the QNX SDK.
Qt Creator creates the necessary boilerplate files. Some of the files are specific to a particular target platform.
注意: If you have not installed the Qt Virtual Keyboard module when you installed Qt, an error message will appear when you try to open the main.qml 在 Form Editor in the Design mode. You can use the Qt Maintenance Tool to install Qt Virtual Keyboard.
注意: Kits are listed if they have been specified in 工具 > Options > Kits (on Windows and Linux) or in Qt Creator > Preferences > Kits (on macOS). For more information, see Adding Kits .
For the Empty and Scroll applications, Qt Creator creates a QML file, main.qml , that you can modify in the Form Editor 或 文本编辑器 .
For the Stack and Swipe applications, Qt Creator generates two UI files, Page1Form.ui.qml and Page2Form.ui.qml , that you can modify in the Form Editor and a QML file, main.qml , that you can modify in the 文本编辑器 to add the application logic.
The Qt for Python - Qt Quick Application - Empty wizard enables you to create a Python project that contains a main QML file. Specify the minimum PySide version to run the application.
The wizard adds the following imports to the source file to provide access to QGuiApplication and QQmlApplicationEngine :
import sys import os from PySide2.QtGui import QGuiApplication from PySide2.QtQml import QQmlApplicationEngine
The wizard also adds a main function, where it creates a QGuiApplication instance and passes system arguments to the QGuiApplication 对象:
if __name__ == "__main__":
app = QGuiApplication(sys.argv)
...
The following lines in the main class create a QQmlApplicationEngine instance and load the generated QML file to the engine object:
engine = QQmlApplicationEngine() engine.load(os.path.join(os.path.dirname(__file__), "main.qml"))
Finally, the wizard adds code that checks whether the file was successfully loaded. If loading the file fails, the application exits with an error code. If loading succeeds, the wizard calls the
app.exec_()
method to enter the Qt main loop and start executing the Qt code:
if not engine.rootObjects():
sys.exit(-1)
sys.exit(app.exec_())
Open the .qml file in the Design mode to design a Qt Quick UI in Qt Quick Designer.
Qt Quick UI Prototype projects are useful for testing or prototyping user interfaces, or for setting up a separate project just for QML editing, for example. You cannot use them for application development, because they do not contain:
For more information about how to turn Qt Quick UI Prototype projects into Qt Quick Application projects, see Converting UI Projects to Applications .
To create a Qt Quick UI Prototype project:
You can add imports later to combine Qt Quick basic types with Qt Quick Controls, Qt Quick Dialogs, and Qt Quick Layouts (available since Qt 5.1).
注意: If you have not installed the Qt Virtual Keyboard module when you installed Qt, an error message will appear when you try to open the main.qml 在 Form Editor in the Design mode. You can use the Qt Maintenance Tool to install Qt Virtual Keyboard.
注意: Kits are listed if they have been specified in 工具 > Options > Kits (on Windows and Linux) or in Qt Creator > Preferences > Kits (on macOS). For more information, see Adding Kits .
Qt Creator creates the following files:
To use JavaScript and image files in the application, copy them to the project folder.