QML无效的属性名称 “signal” M16

huangapple go评论60阅读模式
英文:

QML invalid property name "signal" M16

问题

我跟随了一个关于QML开发的教程(如果感兴趣,可以点击这个链接:https://www.youtube.com/watch?v=aMEQji7Rwrg ),在创建第一个屏幕对话框时,他使用信号来连接onClicked信号来打开对话框,关闭对话框时也是一样的。但在我的代码中,这种方法不起作用,我收到了消息:"无效的属性名称"signal"。我尝试了一段时间的谷歌搜索,但没有找到有用的信息。

以下是出现问题的QML文件中的代码。如果需要,我还可以添加更多代码,但这就是问题出现的地方。

import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Window 2.15

Rectangle
{
    id: heatSelectDialog
    signal: destroyMe()
    anchors.fill: parent
    color: Qt.rgba(0, 0, 0, 0)

    MouseArea
    {
        anchors.fill: parent
        onClicked: heatSelectDialog.destroyMe();
    }

    Rectangle
    {
        id: innerRectangle
        width: parent.width / 2
        height: parent.height * 0.8
        color: "black"
        border.color: "red"
        border.width: 3
    }
}

错误发生在这一行:signal: destroyMe

感谢您的帮助。

Kind regards,

Rolf Hausen

英文:

i follow a tutorial about QML Development
(in case of interest this one: https://www.youtube.com/watch?v=aMEQji7Rwrg )

at creating a first inscreen dialog he is using signal to connect the onClicked Signal
to open the dialog and the same for destroying it.

But in my Code this does not work and i get the message: "invalid property name "signal"
i tried to google this a while but i did not find anything helpful.

Here is the code from the qml file where it appears.
If needed i can also add more code. but this is where the issue appears.

import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Window 2.15

Rectangle
{
    id: heatSelectDialog
    signal: destroyMe()
    anchors.fill: parent
    color: Qt.rgba(0, 0, 0, 0)

    MouseArea
    {
        anchors.fill: parent
        onClicked: heatSelectDialog.destroyMe();
    }

    Rectangle
    {
        id: innerRectangle
        width: parent.width /2
        height: parent.height * 0.8
        color: "black"
        border.color: "red"
        border.width: 3

    }
}

The error happens on the line: signal: destroyMe

i will be thanksful for your help

kind regards

Rolf Hausen

答案1

得分: 0

你在声明信号时有个拼写错误。那里不应该有冒号。所以不应该是这样的:

signal: destroyMe()

你应该使用这样的方式:

signal destroyMe()
英文:

You have a typo in the way that you declared your signal. There should not be a colon there. So rather than this:

signal: destroyMe()

You should be using this:

signal destroyMe()

huangapple
  • 本文由 发表于 2023年2月7日 02:38:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/75365331.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定