QEvent in qml
Is there a way to pass a QEvent, QKeyEvent or QMouseEvent from c++ to qml without writing my own wrapper classes?
6 replies
Thanks Michael
I implemented wrappers similar to the ones in qdeclarativeevents_p.h but when I try to use them in my qml I get this error:
QMetaProperty::read: Unable to handle unregistered datatype ‘QMLKeyEvent*’ for property ‘QDeclarativeBoundSignalParameters::event’
I register the QMLKeyEvent class with this call:
- qmlRegisterType<QMLKeyEvent>();
And at the end of my header file that contains the QMLKeyEvent class I put:
- QML_DECLARE_TYPE(QMLKeyEvent)
Is there something else I need to do to register this type?
I believe I’m using Qt 4.7.1.
My QML code looks like this:
- UserEventFilter {
- id: userEventFilter;
- onKeyPressed: {
- console.log(event.text);
- }
- }
UserEventFilter code looks like this:
- ke.setAccepted(false);
- emit keyPressed(&ke);
- emit userEventOccurred();
- return ke.isAccepted();
- }
I’m going to upgrade to Qt 4.7.2 and see what happens.
You must log in to post a reply. Not a member yet? Register here!



