Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How can I connect to swipe.opened() from C++?



  • I want to connect a C++ slot to the swipe.opened() signal of the SwipeDelegate QML type. I tried it this way:

    QObject::connect(swipeDelegate, SIGNAL(opened()), &cb, SLOT(on_open_swipe()));
    

    but get the following runtime error:

    No such signal SwipeDelegate_QMLTYPE_0::opened() in...

    I also tried

    QObject::connect(swipeDelegate, SIGNAL(swipe.opened()), &cb, SLOT(on_open_swipe()));
    

    but get the same result.


  • Qt Champions 2017

    Best thing is to expose the cb object to qml side using setContextProperty. Use onOpener(..) signal handler to connect with your slot in cb.



  • I would prefer QML not having to know about the C++ side. A solution would be to provide a handler in QML and emit a custom signal from therein. I already did that.
    But I should maybe rephrase my question: while I am able to connect to pressed() or clicked() signals from C++, there is a problem with swipe.opened(), most likely because of the "swipe.". Is there a way to connect as though opened() would directly belong to SwipeDelegate? If not, it would seem to be an omission in the mechanism.


Log in to reply