qprocess

Checking whether qprocess has finished

廉价感情. 提交于 2020-05-18 12:03:58
问题 I have to check whether my process has finished and I need to convert it to bool because I want to you if. In MainWindow.h I have created an object QProcess *action; In mainwindow.cpp void MainWindow:: shutdown() { action=new QProcess(this); action->start("shutdown -s -t 600"); //and now I want to use if if (action has finished) { QMessageBox msgBox; msgBox.setText("Your computer will shutdown in 1 minute."); msgBox.exec(); } 回答1: You should connect to the process's finished signal. Your code

Pyside QProcess Need Help

青春壹個敷衍的年華 提交于 2020-03-24 03:56:32
问题 NOTE : class MyWindow(QWidget): In init self.proc = QtCore.QProcess(self) self.te = QTextEdit(self) self.btn = QPushButton("Execute", self) self.btn.clicked.connect(self.__event_btn) Now I have this: def __event_btn(self): w_dir = "" # This set to my working directory where my C files are args = ["-o", "MyFile", "MyFile.c"] cmd = "gcc" self.proc.setWorkingDirectory(dir) self.proc.readyReadStandardOutput.connect(self.__read) self.proc.closeWriteChannel() self.proc.setReadChannel(QtCore

PyQt4 QProcess.startDetached() - can't get return value and PID of spawned process

ぐ巨炮叔叔 提交于 2020-02-25 08:20:36
问题 This is a follow-up question to a previous one (again posted by me): PyQt4 QProcess state always 0, various slots not working too The code (modified): Main application: qprocess_test.py #!/usr/bin/python import sys from PyQt4 import QtGui, QtCore from PyQt4.QtCore import QProcess class Example(QtGui.QWidget): def __init__(self): super(Example, self).__init__() self.command = "./testCommand.py" self.args = [""] self.initUI() def initUI(self): hbox = QtGui.QHBoxLayout() hbox.addStretch(1) qbtn

How to start a Shell Script with QProcess?

守給你的承諾、 提交于 2020-01-21 11:43:39
问题 How can I start a Shell Script using QProcess? The Shell Script has eight different commands in it, some with arguments others without. I tried to start the Shell Script with (using Ubuntu 11.10): QProcess *Prozess = new QProcess(); Prozess->setWorkingDirectory(MainDirectory); Prozess->start("/bin/sh", QStringList() << "Shell.sh"); But this doesn't work, that means nothing happens. How to make it work? 回答1: Code is fine. Problem is at run-time. Either your program can't run /bin/sh for some

PyQt4 QProcess state always 0, various slots not working too

你。 提交于 2020-01-07 03:57:16
问题 I am trying to figure out the way QProcess ( Linux !) works because I'm going to need it for a project of mine (Note: suprocess or multithreading is not to be used! The process also has to be detached from the main application!). Here is a small code to demonstrate some basic functionality: #!/usr/bin/python import sys from PyQt4 import QtGui, QtCore from PyQt4.QtCore import QProcess class Example(QtGui.QWidget): def __init__(self): super(Example, self).__init__() self.myProcess = QProcess

QProcess read and write

ⅰ亾dé卋堺 提交于 2020-01-04 05:41:47
问题 I am trying to read and write from a qprocess right now. I made a little test program that takes input and redisplays it on the screen in a loop. Here is my code from Qt QString path = "./test"; tcd = new QProcess(this); QStringList args; args << ""; tcd->start(path,args); if(!tcd->waitForStarted(3000)) { stdoutput->append("<h1><font color=red>There was a problem starting the software, please try running the program again.</font></h1>"); } tcd->write("hello\n"); tcd->write("hello\n"); tcd-

Using QProcess.finished() in Python 3 and PyQt

独自空忆成欢 提交于 2020-01-02 09:27:58
问题 How can I use the QProcess.finished() to call a different Python3 script. Here's the script I call: #!/usr/bin/python from PyQt4.QtGui import QApplication from childcontrolgui import childcontrolgui def main(): import sys app = QApplication(sys.argv) wnd = childcontrolgui() wnd.show() sys.exit(app.exec_()) if __name__ == '__main__': main() To call the script I use the code as seen here def properties(self): command="python3 ../GUI/main.py" self.process=QProcess() self.process.finished.connect

Qt - Wait for Qprocess to finish

别等时光非礼了梦想. 提交于 2020-01-01 03:14:23
问题 I'm using CMD by QProcess but I have a problem. My code: QProcess process; process.start("cmd.exe"); process.write ("del f:\\b.txt\n\r"); process.waitForFinished(); process.close(); When I don't pass an argument for waitForFinished() it waits for 30 secs. I want to terminate QProcess after CMD command is executed! Not much and not less! 回答1: You need to terminate the cmd.exe by sending exit command, otherwise it will wait for commands Here is my suggestion: QProcess process; process.start(

Unable to start g++ using QProcess

浪尽此生 提交于 2019-12-25 02:11:58
问题 I want to compile a c++ file from Qt application by using QProcess. But it is not working, I don't see any .o or .exe file generated by the compiler. Here is what I am doing - QProcess *process = new QProcess(this); QString program = "g++"; QStringList arguments; //fileName is fetched from QFileDialog arguments << fileName << "-o" << QFileInfo(fileName).path() + QFileInfo(fileName).baseName() + ".exe"; errorFilename = QFileInfo(fileName).baseName() + "_error.txt"; process-

Pyside: Multiple QProcess output to TextEdit

試著忘記壹切 提交于 2019-12-24 10:35:39
问题 I have a pyside app that calls an exectuable. I want to run this executable asynchronously in n processes and capture the output of each process in a QTextEdit. At the moment I have: def run(self, args, worklist): self.viewer = OutputDialog(self) self.procs = [] for path in worklist: final_args = args + path p = QtCore.QProcess(self) p.readyReadStandardOutput.connect(self.write_process_output) self.procs.append(p) p.start(self.exe, final_args) def write_process_output(self): for p in self