[英]Qt Quick signal not emitted
EDIT编辑
I didn't found a way to access the active instance of the Class-Object so I transfered all Q_PROPERTIES
into one Class, which lets them interact which each other.我没有找到访问 Class-Object 的活动实例的方法,所以我将所有
Q_PROPERTIES
转移到一个 Class 中,这样它们就可以相互交互了。 Not so clean and OOP-ish but it works.不是那么干净和OOP-ish,但它可以工作。
I have a class where I receive data from an REST-Call.我有一个 class 从 REST-Call 接收数据。 With this data, I'd like to call
Q_PROPERTY
Setter-Function of another class, which works fine.有了这些数据,我想调用另一个 class 的
Q_PROPERTY
Setter-Function,它工作正常。 I can read my properties in Debug-Mode.我可以在调试模式下读取我的属性。 But one thing is not working: calling the
Q_PROPERTY
-Setter-Functions from another class, will not emitting the signal (normally triggered when this property has been changed).但有一件事不起作用:从另一个 class 调用
Q_PROPERTY
-Setter-Functions,不会发出信号(通常在更改此属性时触发)。
I am using the Q_PROPERTY
with read, write notify functionality ( Q_PROPERTY(QUuid id READ getId WRITE setId NOTIFY idChanged
). After initalizing the Class via qmlRegisterType<VF_Kiste>("qt.kiste", 1,0, "Kiste");
in main.cpp
I can access the property in QML.我正在使用具有读写通知功能的
Q_PROPERTY
( Q_PROPERTY(QUuid id READ getId WRITE setId NOTIFY idChanged
)。通过qmlRegisterType<VF_Kiste>("qt.kiste", 1,0, "Kiste");
后main.cpp
我可以访问 QML 中的属性。
Setter:二传手:
void VF_Kiste::setId(const QUuid& id)
{
if (id == _id)
return;
_id = id;
emit idChanged();
}
So calling this Setter-Function will change the property (I tried this and it works) but is not emitting the signal I need for the QML-Part.所以调用这个 Setter-Function 会改变属性(我试过这个并且它有效)但不会发出我需要的 QML-Part 信号。 Here is where I call the setter.
这是我调用setter的地方。
VF_Kiste* kst = new VF_Kiste();
...
kst->setId(...);
In QML I'd like to call the onIdChanged()
-Function of this described function, but without emitting the signal I cannot access the changed value of the property.在 QML 中,我想调用描述的 function 的
onIdChanged()
-函数,但如果不发出信号,我无法访问属性的更改值。
Also I tried calling the Q_PROPERTY
from QML directly and not from the inherited class, this works as well, so the problem is in calling the setter from another class.我还尝试直接从 QML 调用
Q_PROPERTY
,而不是从继承的 class 调用 Q_PROPERTY,这也可以,所以问题在于从另一个 class 调用设置器。
EDIT编辑
I didn't found a way to access the active instance of the Class-Object so I transfered all Q_PROPERTIES
into one Class, which lets them interact which each other.我没有找到访问 Class-Object 的活动实例的方法,所以我将所有
Q_PROPERTIES
转移到一个 Class 中,这样它们就可以相互交互了。 Not so clean and OOP-ish but it works.不是那么干净和OOP-ish,但它可以工作。
I have a class where I receive data from an REST-Call.我有一个 class 从 REST-Call 接收数据。 With this data, I'd like to call
Q_PROPERTY
Setter-Function of another class, which works fine.有了这些数据,我想调用另一个 class 的
Q_PROPERTY
Setter-Function,它工作正常。 I can read my properties in Debug-Mode.我可以在调试模式下读取我的属性。 But one thing is not working: calling the
Q_PROPERTY
-Setter-Functions from another class, will not emitting the signal (normally triggered when this property has been changed).但有一件事不起作用:从另一个 class 调用
Q_PROPERTY
-Setter-Functions,不会发出信号(通常在更改此属性时触发)。
I am using the Q_PROPERTY
with read, write notify functionality ( Q_PROPERTY(QUuid id READ getId WRITE setId NOTIFY idChanged
). After initalizing the Class via qmlRegisterType<VF_Kiste>("qt.kiste", 1,0, "Kiste");
in main.cpp
I can access the property in QML.我正在使用具有读写通知功能的
Q_PROPERTY
( Q_PROPERTY(QUuid id READ getId WRITE setId NOTIFY idChanged
)。通过qmlRegisterType<VF_Kiste>("qt.kiste", 1,0, "Kiste");
后main.cpp
我可以访问 QML 中的属性。
Setter:二传手:
void VF_Kiste::setId(const QUuid& id)
{
if (id == _id)
return;
_id = id;
emit idChanged();
}
So calling this Setter-Function will change the property (I tried this and it works) but is not emitting the signal I need for the QML-Part.所以调用这个 Setter-Function 会改变属性(我试过这个并且它有效)但不会发出我需要的 QML-Part 信号。 Here is where I call the setter.
这是我调用setter的地方。
VF_Kiste* kst = new VF_Kiste();
...
kst->setId(...);
In QML I'd like to call the onIdChanged()
-Function of this described function, but without emitting the signal I cannot access the changed value of the property.在 QML 中,我想调用描述的 function 的
onIdChanged()
-函数,但如果不发出信号,我无法访问属性的更改值。
Also I tried calling the Q_PROPERTY
from QML directly and not from the inherited class, this works as well, so the problem is in calling the setter from another class.我还尝试直接从 QML 调用
Q_PROPERTY
,而不是从继承的 class 调用 Q_PROPERTY,这也可以,所以问题在于从另一个 class 调用设置器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.