qprocess

How to check if a program is running by its name with Qt (C++)

旧街凉风 提交于 2019-12-03 02:59:04
How to check if a program is running, by its name, with Qt (C++). Will QProcess::pid do the job? I don't know how to use it. Please suggest. As far as I know QProcess won't allow you to do that (unless you've spawned the process yourself) and in fact nothing in Qt will. However Win32 API provides a way to achieve what you want through EnumProcesses function and a complete example of how to use it is provided at Microsoft website: http://msdn.microsoft.com/en-us/library/ms682623.aspx To get you need replace PrintProcessNameAndID with the following function: bool matchProcessName( DWORD

How to execute complex linux commands in Qt? [duplicate]

☆樱花仙子☆ 提交于 2019-12-02 21:12:46
This question already has answers here : Piping (or command chaining) with QProcess (4 answers) I want to restart the computer by running a command in linux using QProcess . I have hard-coded my root password in my application. When i run the following in a terminal it works perfect: echo myPass | sudo -S shutdown -r now When i put the command in a shell script and call it via QProcess it is also successful : QProcess process; process.startDetached("/bin/sh", QStringList()<< "myScript.sh"); But i can not run it by directly passing to QProcess : process.startDetached("echo myPass | sudo -S

Change PATH environment variable for cmd.exe with QProcessEnvironment

妖精的绣舞 提交于 2019-12-02 11:12:01
I want to start cmd.exe from a Qt app with a specific PATH set. I insert "Path" in QProcessEnvironment and set that environment to QProcess. Then I startDetached "cmd". On the command prompt, the path is the same as the from the calling app, not what I just set. Did I miss something? I use Qt 5.2.0 with mingw and Qt-creator 3.0.0 on windows 8.1.s QProcess process(this); QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); env.insert("Path", "MyPath"); process.setProcessEnvironment(env); QStringList args; args << "/D" << "/K" << "dir"; process.startDetached("cmd", args); David

QProcess unknown error

☆樱花仙子☆ 提交于 2019-12-02 09:33:23
问题 I got strange problem. QProcess just not working! And error is unknown. I got global var in header QProcess *importModule; An I got this function ( I tried both start and startDetached methods btw ) void App::openImport(){ importModule = new QProcess(); importModule->setWorkingDirectory(":\\Resources"); importModule->startDetached("importdb_module.exe"); QMessageBox::information(0,"",importModule->errorString()); } It jsut outputs that error is unknown . Also it wont start other exes like

Terminate an ongoing QProcess that is running inside a QThread? [duplicate]

我的未来我决定 提交于 2019-12-02 07:08:39
This question already has an answer here: Ensuring QProcess termination on termination of its parent QThread 2 answers how to terminate an ongoing QProcess that is running inside a QThread and gets deleted by another QThread? I even inserted a QMutex extCmdProcessLock, which should avoid the destruction of the DbManager before the extCmdProcess could finish or timeout. I get a segmentation fault on "waitForStarted" if another thread calls delete on DbManager. I cannot use signals (I think) because I use the external command inside a sequential data process. Thank you very much for any help!

How to detect when ssh connection (over a QProcess) has finished?

大城市里の小女人 提交于 2019-12-02 05:38:55
I am running an ssh tunnel from an application using a QProcess : QProcess* process = new QProcess(); process->start("ssh", QStringList()<<"-L"<<"27017:localhost:27017"<<"example.com"); So far it works great, the only problem being that there is no way for me to see when the port has actually been created. When I run the command on a shell, it takes about 10 seconds to connect to the remote host after which the forwarded port is ready for usage. How do I detect it from my application? EDIT: As suggested by vahancho, I used the fact that post-connection there is some output on the terminal that

QProcess unknown error

不想你离开。 提交于 2019-12-02 04:23:11
I got strange problem. QProcess just not working! And error is unknown. I got global var in header QProcess *importModule; An I got this function ( I tried both start and startDetached methods btw ) void App::openImport(){ importModule = new QProcess(); importModule->setWorkingDirectory(":\\Resources"); importModule->startDetached("importdb_module.exe"); QMessageBox::information(0,"",importModule->errorString()); } It jsut outputs that error is unknown . Also it wont start other exes like void App::openImport(){ importModule = new QProcess(); importModule->setWorkingDirectory("C:\\Program

Real time display of QProcess output in a textBrowser

ぐ巨炮叔叔 提交于 2019-12-01 21:18:31
I am a newbie in qt development and i want to transfer the output of QProcess to a textBrowser in real time. I started by executing a simple echo command,but the output of the program is not getting displayed. What am i doing wrong???? QProcess p; p.start("echo hye"); QByteArray byteArray = p.readAllStandardOutput(); QStringList strLines = QString(byteArray).split("\n"); QString line= p.readAllStandardOutput(); if(p.state()==QProcess::NotRunning) ui->textBrowser->append("not running"); foreach (QString line, strLines){ ui->textBrowser->append(line);} P.S. I am on a linux machine. EDIT: I am

QProcess fails to execute external executable

会有一股神秘感。 提交于 2019-12-01 17:39:16
问题 I am struggling to find a solution to my problem, but I simply have no clue how to solve it. I am creating an user-interface for some programs I made (so you can through simply pressing a button start an executable). So I thought of using qt. So I read a lot about the QProcess and tried to use it. At the first executable of mine I tried to start it through QProcess::start(), but it didn't work so I tried it with QProcess:execute(): QProcess *proc = new QProcess(this); QDir::setCurrent("C:\

QProcess and shell : Destroyed while process is still running

…衆ロ難τιáo~ 提交于 2019-12-01 08:20:55
I want to launch a shell script with Qt. QProcess process; process.start(commandLine, QStringList() << confFile); process.waitForFinished(); if(process.exitCode()!=0) { qDebug () << " Error " << process.exitCode() << process.readAllStrandardError(); } else { qDebug () << " Ok " << process.readAllStrandardOutput() << process.readAllStrandardError(); } The result is : Ok : Result.... " "" QProcess : Destroyed while process is still running. This message does not appear every time. What is the problem? process.waitForFinished(); is hitting the default 30 seconds timeout. Use process