Application QML Type (Singleton)
提供对许多 QML 组件共享的全局应用程序状态属性的访问。更多...
| Import Statement: | import QtQuick |
注意:此类型是 QML 单例。QML 引擎中仅存在一个此类实例。
属性
- arguments : list<string>
- displayName : string
- domain : string
- font : font
- layoutDirection : enumeration
- name : string
- organization : string
- screens : list<Screen>
- state : enumeration
- styleHints : StyleHints
- supportsMultipleWindows : bool
- version : string
信号
详细说明
Application 单例向 QML 应用程序公开了QApplication 的一部分属性。
它还提供了一个aboutToQuit()信号,该信号与QCoreApplication::aboutToQuit()功能相同。
import QtQuick
Window {
id: root
visible: true
width: 800
height: 680
title: `${Application.name} (${Application.version})`
Connections {
target: Application
function onAboutToQuit() {
console.log("Bye!")
}
}
}另请参阅 SystemPalette 。
属性文档
arguments : list<string>
这是一个字符串列表,包含调用该可执行文件时传入的参数。
displayName : string
该属性表示在QGuiApplication 实例上设置的应用程序显示名称。可以通过写入该属性来设置应用程序显示名称。
Binding {
target: Application
property: "displayName"
value: "My Awesome Application"
}domain : string
这是在QCoreApplication 实例上设置的组织域名。可以通过写入该属性来设置组织域名。
font : font [read-only]
返回由QGuiApplication::font() 函数返回的默认应用程序字体。
layoutDirection : enumeration [read-only]
此只读属性可用于查询应用程序的默认布局方向。系统启动时,默认布局方向取决于应用程序的语言。在文本和图形元素从右向左阅读的语言环境中,该属性的值为Qt.RightToLeft ;而在从左向右阅读的语言环境中,其值为Qt.LeftToRight 。 您可以绑定此属性,以自定义应用程序布局,从而同时支持这两种布局方向。
有关可能的值,请参阅 C++ 中的Qt::LayoutDirection 枚举。
RowLayout {
layoutDirection: Application.layoutDirection
}name : string
这是在QCoreApplication 实例上设置的应用程序名称。可以通过写入此属性来设置应用程序名称。
organization : string
这是在QCoreApplication 实例上设置的组织名称。可以通过写入此属性来设置组织名称。
screens : list<Screen> [read-only]
一个包含所有已连接屏幕描述的数组。 该数组的元素是与Screen 关联对象具有相同属性的对象。实际上,该数组对应于QGuiApplication::screens()返回的屏幕列表。除了检查名称、宽度、高度等属性外,还可以将数组元素赋值给Window项的screen属性,从而作为C++端QWindow::setScreen()函数的替代方案。
另请参阅 Screen 、Window 以及Window.screen 。
state : enumeration [read-only]
该属性表示应用程序的当前状态。
有关可能的取值,请参阅 C++ 中的 `Qt::ApplicationState ` 枚举。
Timer {
interval: 1000; repeat: true
active: Application.state === Qt.ApplicationActive
onTriggered: imageFetcher.fetchLatestImages()
}styleHints : StyleHints [read-only]
styleHints 属性提供特定于平台的样式提示和设置。有关更多详细信息,请参阅QStyleHints 文档。
以下示例使用styleHints 来确定项目应在鼠标点击时还是触摸释放时获得焦点:
import QtQuick
MouseArea {
id: button
onPressed: {
if (!Application.styleHints.setFocusOnTouchRelease)
button.forceActiveFocus()
}
onReleased: {
if (Application.styleHints.setFocusOnTouchRelease)
button.forceActiveFocus()
}
}supportsMultipleWindows : bool [read-only]
如果平台支持多窗口,则返回true 。例如,某些嵌入式平台不支持多窗口。
version : string
这是在QCoreApplication 实例上设置的应用程序版本。可以通过写入此属性来设置应用程序版本。
Signal 文档
aboutToQuit()
当应用程序即将退出主事件循环时,会发出此信号。如果您的应用程序需要进行一些最后时刻的清理工作,该信号特别有用。在此状态下无法进行用户交互。有关更多信息,请参阅Window.closing 。
注意: 相应的处理程序 为onAboutToQuit 。
© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.