QT快速UI表单不支持函数

functions are not supported in Qt Quick ui form

本文关键字:不支持 函数 表单 UI 快速 QT      更新时间:2023-10-16

我正在尝试在QT快速应用程序中打开一个链接,我得到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 {
}

根据文档:

您可以使用QT创建者向导创建具有文件名扩展名.UI.QML的UI表单。UI形式包含QML语言的纯声明子集。建议您在设计模式下编辑表单。但是,将项目作为别名属性是一个仅商业功能,因此,如果您使用QT Creator的开源版本,则必须使用编辑模式来执行此操作。QT创建者通过显示错误消息来强制使用受支持的QML功能。

不支持以下功能:

  • JavaScript块
  • 功能定义
  • 函数呼叫(QSTR除外)
  • 纯表达式以外的其他绑定
  • 信号处理程序
  • 除根项目以外的其他项目中的状态
  • 未从qquickitem或item item
  • 派生的根项目

不支持以下类型:

  • 行为
  • 绑定
  • 画布
  • 组件
  • 着色器效果
  • 计时器
  • 变换
  • 过渡

我建议的解决方案是用以下内容抑制警告:

// @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-javascript-and-javascript-and-qml-checks

关于form.ui.qml

// add this:    
property alias license: license    
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
        // Remove this line

    MouseArea {
        anchors.fill: parent
        acceptedButtons: Qt.NoButton
        cursorShape: parent.hoveredLink ? Qt.PointingHandCursor : Qt.ArrowCursor
    }
}

大约qml

import QtQuick 2.4
AboutForm {
     // add this line
     license.onLinkActivated: Qt.openUrlExternally("https://www.gnu.org/licenses/old-licenses/gpl-2.0.html")
}

qt快速UI表单应该是一个只有可见元素的QML文件。这里没有商业逻辑(qt-forum)。

使用QT创建者创建QT快速UI表单时,它将创建两个文件:

  1. youritemform.ui.qml
  2. youritem.qml&lt; ---这包括逻辑。

YourItem.qml

YourItemForm {
  button1 {
    text: data_provider.get("button_text")
  }
}

YourItemForm.ui.qml

Item {
  property alias button1 : button1 
  Button {
    id: button1
  }
}

我建议从main.qml开放外部链接,而不是从UI本身打开。

在aboutform.ui.qml中添加

属性int Internexall:1

        MouseArea {
            id: mousearea
            anchors.fill: parent
            drag.target: parent
            onClicked: externalcall=2
        }

然后在Main.QML应用程序窗口内部创建一个On On On On On OfectionCall更改,并在此功能中打开链接。如果不清楚,请让我知道一个例子。