c++ - Qt Quick ui形式不支持功能

标签 c++ qt qtquick2

我试图在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")

引用文献:
  • https://forum.qt.io/topic/66429/what-is-sign-in-disable-check-m16
  • http://doc.qt.io/qtcreator/creator-checking-code-syntax.html#list-of-javascript-and-qml-checks
  • 关于c++ - Qt Quick ui形式不支持功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47742009/

    相关文章:

    javascript - SpiderMonkey 对比 JavaScriptCore 对比?

    c++ - QPluginLoader 实例总是返回 null

    Python pyqt : background images

    与 Qt 4 (QtQuick 1.x) 和 Qt 5 (QtQuick 2.x) 兼容的 C++/QML 项目

    c++ - boost::make_shared<T[]> 值初始化还是默认初始化数组?

    c++ - 对 C++ 中的虚拟基类感到困惑

    c++ - 在派生类的对象上使用指向基类成员函数的指针

    c++ - 如何在 Qt 中弹出消息窗口?

    android - 在 Qt/QML 中,如何为不同的设备密度加载不同的图像 (Android)

    qt - 如何使用 QML 在父 MouseArea 中包含子鼠标悬停事件?