简体   繁体   中英

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.

This is what I have tried without success:

QML:

MultiPointTouchArea  {
  minimumTouchPoints: 1
  maximumTouchPoints: 2

  touchPoints: [
    TouchPoint { id: touch1 },
    TouchPoint { id: touch2 }
  ]

  onPressed: {
    myCPlusPlusClass.onPressed(touchPoints)
  }
}

C++:

void myCPlusPlusClass::onPressed(const QList<QTouchEvent::TouchPoint>& list) 
{
  // Do something
}

I have registered QListQTouchEvent::TouchPoint as a metatype like so:

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.

My second best option would be to pass the TouchPoints individually (not in a list).

Is this possible to solve? If not, what are my options to pass all information from a TouchPoint to C++ side?

I think a way could be to pass to C++ an easily parsable 'report' about the component state. Dunno right now which properties there are in TouchPoint(s), but presumably dumping them to text seems easily feasible (maybe using Array.join). Then parse back from C++ and use that data.

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.

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.

A saner approach would include an interface that would receive the relevant input information only.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM