我试图在Qt Quick应用程序中打开一个链接,收到functions are not supported in Qt Quick ui form
警告,该应用程序正常工作,我想摆脱该警告,如何解决此警告?AboutForm.ui.qml
文件
Text {
id: license
x: 40
y: 207
color: "#ffffff"
text: qsTr("<a href='https://www.gnu.org/licenses/old-licenses/gpl-2.0.html'>GNU General Public License, version 2 or later</a>")
font.pixelSize: 16
// the editor complains about this function
onLinkActivated: Qt.openUrlExternally("https://www.gnu.org/licenses/old-licenses/gpl-2.0.html")
MouseArea {
anchors.fill: parent
acceptedButtons: Qt.NoButton
cursorShape: parent.hoveredLink ? Qt.PointingHandCursor : Qt.ArrowCursor
}
}
我的
About.qml
文件为空。import QtQuick 2.4
AboutForm {
}
最佳答案
根据docs:
You can use Qt Creator wizards to create UI forms that have the filename extension .ui.qml. The UI forms contain a purely declarative subset of the QML language. It is recommended that you edit the forms in the Design mode. However, exporting items as alias properties is a commercial only feature, and therefore you must use the Edit mode to do it if you are using the open source version of Qt Creator. Qt Creator enforces the use of the supported QML features by displaying error messages.
The following features are not supported:
- JavaScript blocks
- Function definitions
- Function calls (except qsTr)
- Other bindings than pure expressions
- Signal handlers
- States in other items than the root item
- Root items that are not derived from QQuickItem or Item
The following types are not supported:
- Behavior
- Binding
- Canvas
- Component
- Shader Effect
- Timer
- Transform
- Transition
我建议的解决方案是通过以下方式禁止显示警告:
// @disable-check M222
onLinkActivated: Qt.openUrlExternally(
"https://www.gnu.org/licenses/old-licenses/gpl-2.0.html")
引用文献:
关于c++ - Qt Quick ui形式不支持功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47742009/