Unsolved calling python from qt c++
i want to call a python code from qt c++ and give it some float parameters, how can i do this in qt and how should the python file which is call look like?
Depends whether you intend the Python code to be an external script or an embedded interpreter in the Qt C++ app. Which probably depends on what you want it to do. Always assuming you don't want your Qt app to be written in Python + Qt itself.
python code is external script not embedded in the qt and it takes parameters 4 float variables so i want to call this script which takes the input and do lots of work and algorithm depends on many libraries in python the return a result
i tried first a code like this to ensure that qt can call a python file
QString pythonPath = "C:/Python27/python.exe";
QString pythonScript = "C:/Users/maboelamayem/PycharmProjects/testqt.py";
params << pythonScript; p.start(pythonPath, params); p.waitForFinished(-1); QString p_stdout = p.readAll(); QString p_stderr = p.readAllStandardError(); if(!p_stderr.isEmpty()) qDebug()<<"Python error:"<<p_stderr; qDebug()<<"Python result="<<p_stdout;
but it gives error : Python error: "C:\Python27\python.exe: can't open file 'C:/Users/maboelamayem/PycharmProjects/testqt.py': [Errno 2] No such file or directory\r\n"
okay i missed main in the python code but now my python code is :
if name == "main":
but the error in qt is
Python error: "C:\Python27\python.exe: can't find 'main' module in 'C:/Users/maboelamayem/PycharmProjects/testqt'\r\n"
so am i writing the function in python code wrongly?
hey, i solved this problem but i want now to send parameters to the main function in the python code but p.start() is not used for this so what is the other option to send parameters or arguments to the python function
but p.start() is not used for this
Yes it is. Why not look at the docs: https://doc.qt.io/qt-5/qprocess.html#start and https://doc.qt.io/qt-5/qprocess.html#running-a-process
please can I get your contact number I am working on an industrial robot and I am stuck with the same thing you did! It is urgent. Thank you