Qt and QtPy in one program



  • Hi everyone, I am new to Qt and I am actually looking for informations about Qt before using it for my project.
    I would like to know if it is possible to use QT ( C++ ) and QtPy ( Python ) languages in the same program's code?
    Is it possible to call a pythons script (.py) directly from my code in Qt?

    Thanks



  • @Freddykong
    I think you need to clarify just what/why you are trying to do which would require both Qt for C++ and Qt for Python to be run inside a project? It's usual to need just one or the other.

    Is it possible to call a pythons script (.py) directly from my code in Qt?

    You can always run any kind of sub-process, including running some standalone Python script/code, via QProcess::start(). But if that script is intended to access things inside your actual parent program, or use Qt calls to access Qt objects/UI in the calling program, that is a different matter....



  • @Freddykong could you please describe what could be an use case for having both Qt (C++) and Qt (Python) sources at the same application?

    In any case, instead of running the Python script as a separate/child process as suggested by @JonB you may want to embed a Python interpreter in your C++ code



  • I don't know if I got the question right,
    but the kind of interaction you describe could be possible by "extending" and existing Qt/C++ application to use Qt/Python code.

    Take a look at this example: https://code.qt.io/cgit/pyside/pyside-setup.git/tree/examples/scriptableapplication
    There, there is a Qt/C++ Window that shows some Python code which you can run and interact with the Qt/C++ object itself.

    Please be aware that many things need to be consider, and that you must handle the embedded Python and generate Python bindings for your Qt/C++ potion of code that you want to interact with.

    Another use-case which was based on that example, is the research that is currently on-going regarding extending QtCreator with Python:
    https://blog.qt.io/blog/2018/08/15/python-extensions/

    I hope those cases are in the same direction as your question.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.