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

Run some python code from qml button onClicked?



  • Brand new to qml, but is there an example of running some python code when a QML button onClicked?
    Thanks in advance


  • Lifetime Qt Champion

    @ViGor You can't run Python code directly in QML. You will either need to run Python script as external proccess from C++ or embed Python interpreter in your app (also requires C++).



  • @ViGor I don't know if this will fit your requirements but it might be worth looking at PySide, which is a Python-based exposure of Qt. It would probably mean writing your application in Python but I believe that this approach would provide a mechanism for calling from QML to Python, by exposing a slot from Python in the same way that in a C++-based QML project one can interact with slots in the C++ back end. I have no experience of PySide but thought it was worth mentioning in case it might work for you.


Log in to reply