qprocess

How do I read from QProcess?

非 Y 不嫁゛ 提交于 2019-12-05 17:59:29
I have this simple C++ program: int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QProcess ps; QByteArray ba; ps.start("ls J:"); ba = ps.readAllStandardOutput(); char *someData = ba.data(); cout << "Testing QProcess ..." << endl; cout << someData << endl; cout << "done!" << endl; return a.exec(); } The output is: Testing QProcess ... done! If I run "ls J:" from Windows cmd it works. What am I missing? Use QIODevice::waitForReadyRead() in a loop, and only after that returns, then call readAllStandardOutput() . As it says in the docs, QProcess::readAllStandardOutput() will read

Error while connecting lambda function to QProcess::error

荒凉一梦 提交于 2019-12-05 12:03:06
In following code I want to connect lambda function to QProcess::error signal: void Updater::start() { QProcess process; QObject::connect(&process, &QProcess::error, [=] (QProcess::ProcessError error) { qWarning() << "error " << error; }); process.start("MyProgram"); process.waitForFinished(); } But I get strange error: error: no matching function for call to 'Updater::connect(QProcess* [unresolved overloaded function type], Updater::start()::)' }); What I do wrong here? The code executes inside method of class derived from QObject. The project configured to work with c++11. I use Qt 5.3.1 on

How can I direct the output of a QProcess to a file?

ぃ、小莉子 提交于 2019-12-05 06:44:25
I want to have the output of qconf redirected to test_settings.txt in my tmp folder. I've thought of two possibilities: QProcess procWriteProject; procWriteProject.start("qconf", QStringList() << " -sprj " << projectList[0] << " >> " << "\"/tmp/testing.txt\""); procWriteProject.start("qconf -sprj " + projectList[0] + " >> " + "/tmp/test_settings"); Will either of those work? Is there a better way? QProcess procWriteProject; procWriteProject.setStandardOutputFile("/tmp/test_settings.txt"); procWriteProject.start("qconf", QStringList() << "-sprj" << projectList[0]); 来源: https://stackoverflow.com

how to get output system() command in Qt?

自闭症网瘾萝莉.ら 提交于 2019-12-04 09:41:30
问题 I use system() command in Qt. and I want to get output and show it to users. my command is: system("echo '" + rootPass.toAscii() + "' | su - root -c 'yum -y install " + packageName.toAscii() + "'"); this command can't run when I use it in QProcess (start or execute function) but if i can run this command in QProcess i can get output with QProcess::readAllStandardOutput() function. also when i used ">" in system command to save output in a file, I receive output when the package completely

Real time display of QProcess output in a textBrowser

人盡茶涼 提交于 2019-12-04 04:18:13
问题 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");

Embedding a terminal in PyQt5

a 夏天 提交于 2019-12-03 18:07:55
问题 So I've been trying to create my own terminal but that has been proven very glitchy and not professional looking. Then I stumbled across this code which is for PyQt4: #!/usr/bin/env python #-*- coding:utf-8 -*- import sys from PyQt4.QtCore import * from PyQt4.QtGui import * class embterminal(QWidget): def __init__(self): QWidget.__init__(self) self.process = QProcess(self) self.terminal = QWidget(self) layout = QVBoxLayout(self) layout.addWidget(self.terminal) #self.process.start( #'xterm',['

What is the difference between QProcess::start and QProcess::startDetached?

折月煮酒 提交于 2019-12-03 13:58:35
问题 The Qt documentation gives this explanation: QProcess::start : Starts the given program in a new process, if none is already running, passing the command line arguments in arguments. QProcess::startDetached : Starts the program program with the arguments arguments in a new process, and detaches from it. What is the difference between the two? Is the difference only that you can start just one instance of a program using QProcess::start and many instances using QProcess::startDetached ? 回答1:

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

被刻印的时光 ゝ 提交于 2019-12-03 13:35:58
问题 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. 回答1: 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

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

╄→尐↘猪︶ㄣ 提交于 2019-12-03 07:42:33
问题 This question already has answers here : Piping (or command chaining) with QProcess (4 answers) Closed 5 years ago . 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(

What is the difference between QProcess::start and QProcess::startDetached?

孤人 提交于 2019-12-03 03:10:17
The Qt documentation gives this explanation: QProcess::start : Starts the given program in a new process, if none is already running, passing the command line arguments in arguments. QProcess::startDetached : Starts the program program with the arguments arguments in a new process, and detaches from it. What is the difference between the two? Is the difference only that you can start just one instance of a program using QProcess::start and many instances using QProcess::startDetached ? SingerOfTheFall If you use start , termination of the caller process will cause the termination of the called