[英]How to pass list of TouchPoints from QML to C++?
I'm using a MultiPointTouchArea and want to pass the list of touchpoints to C++ side whenever onPressed, onReleased or onUpdated is triggered. 我正在使用MultiPointTouchArea,并且只要触发onPressed,onReleased或onUpdated,就希望将接触点列表传递给C ++端。
This is what I have tried without success: 这是我尝试过没有成功的:
QML: QML:
MultiPointTouchArea {
minimumTouchPoints: 1
maximumTouchPoints: 2
touchPoints: [
TouchPoint { id: touch1 },
TouchPoint { id: touch2 }
]
onPressed: {
myCPlusPlusClass.onPressed(touchPoints)
}
}
C++: C ++:
void myCPlusPlusClass::onPressed(const QList<QTouchEvent::TouchPoint>& list)
{
// Do something
}
I have registered QListQTouchEvent::TouchPoint as a metatype like so: 我已将QListQTouchEvent :: TouchPoint注册为元类型,如下所示:
qRegisterMetaType<QList<QTouchEvent::TouchPoint>>("QList<QTouchEvent::TouchPoint>");
I don't get any errors however the list is just i nullptr or similar on the C++ side. 我没有得到任何错误,但是在C ++方面列表只是我的nullptr或类似的。
My second best option would be to pass the TouchPoints individually (not in a list). 我的第二个最佳选择是单独传递TouchPoints(不在列表中)。
Is this possible to solve? 这有可能解决吗? If not, what are my options to pass all information from a TouchPoint to C++ side?
如果没有,我有什么选择将所有信息从TouchPoint传递到C ++端?
I think a way could be to pass to C++ an easily parsable 'report' about the component state. 我认为一种方法可能是向C ++传递一个关于组件状态的易于解析的“报告”。 Dunno right now which properties there are in TouchPoint(s), but presumably dumping them to text seems easily feasible (maybe using Array.join).
Dunno现在TouchPoint(s)中有哪些属性,但可能会将它们转储到文本中似乎很容易实现(可能使用Array.join)。 Then parse back from C++ and use that data.
然后从C ++解析并使用该数据。
If you really insist to use multi-touch from C++, you could simply intercept the touch events on the C++ side and not bother with the MultiPointTouchArea
whatsoever, I mean if that is literally all you need it for. 如果你真的坚持使用C ++的多点触控,你可以简单地拦截C ++方面的触摸事件,而不用麻烦任何
MultiPointTouchArea
,我的意思是,如果这就是你需要的全部内容。
It is quite the stretch to expect this code to work, the list of types that are implicitly converted back and forth between QML and C++ do not include touch points, much less lists of such. 期望这段代码能够正常工作,在QML和C ++之间来回隐式转换的类型列表不包括触摸点,更不用说这样的列表了。
A saner approach would include an interface that would receive the relevant input information only. 更安全的方法将包括仅接收相关输入信息的接口。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.