executing .py file from qt
hi,
I am writing a Qt application, where i have a "helloworld.py" and "helloworld .ui" file.
but i m getting trouble here, i wanna run /execute this .py file from within the qt application.
i have searched a lot on internet, and came across the QProcess class.
i tried to use it.(used start and execute methods from the class), but i dint get the results,
can anyone pls ans my question.
my code is bellow
Code:
QString scriptFile
= "D://QTDev//QuickEditor//helloworld.py";
process.execute("Python D://QTDev//QuickEditor//helloworld.py");
process.start("cd D://QTDev//QuickEditor//");
process.start("Python D://QTDev//QuickEditor//helloworld.py");
process.waitForFinished(1000);
Code:
from PyQt5 import QtCore, QtGui, QtWidgets
import sys
def __init__(self):
self.setupUi(self)
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(400, 300)
self.verticalLayout.setObjectName("verticalLayout")
self.pushButton.setObjectName("pushButton")
self.verticalLayout.addWidget(self.pushButton)
self.
label = QtWidgets.
QLabel(Form
) self.label.setText("")
self.label.setObjectName("label")
self.verticalLayout.addWidget(self.label)
self.retranslateUi(Form)
def retranslateUi(self, Form):
Form.setWindowTitle(_translate("Form", "Form"))
self.pushButton.setText(_translate("Form", "Press Me!!!"))
self.pushButton.clicked.connect(self.printHello)
def printHello(self):
print( "Hello World !")
if __name__ == '__main__':
ex = Ui_Form();
ex.show();
sys.exit(app.exec_())
Re: executing .py file from qt
The first argument to QProcess::start() is the program you run, the second argument is a list of arguments for that program.
Cheers,
_
Re: executing .py file from qt
First listing line 3: is python on the system PATH? Why are you doubling the forward slashes? This will be passed unchanged to the program: you likely need the native path separators
Line 5. This would not change the directory for the process at line 6 even if it worked.
Re: executing .py file from qt
yes python is there on PATH..
what if i have no argument list.. still i have to give empty?
Re: executing .py file from qt
Quote:
Originally Posted by
prachi kamble
yes python is there on PATH..
what if i have no argument list.. still i have to give empty?
No, there is an overload that does not require the arguments QStringList if you just want to run the Python interpreter without a script.
Cheers,
_
Re: executing .py file from qt
thnx sir,
so it means the following code is correct?
Code:
process.setWorkingDirectory("D:\\QTDev\\QuickEditor");
process.setProgram("python helloworld.py");
process.start("python helloworld.py");
process.waitForFinished(1000);
Re: executing .py file from qt
No, unless you have an executable called "python hellowordl.py", which is highly unlikely, most programs don't have spaces in their program names.
Cheers,
_