C++ (Qt)QString program;QStringList arguments;program="traceroute";arguments << "ya.ru";QProcess myProcess;myProcess.start(program, arguments);myProcess.waitForFinished();myProcess.deleteLater();ui->te->append( QString::fromLocal8Bit(myProcess.readAllStandardOutput()));ui->te->append( QString::fromLocal8Bit(myProcess.readAllStandardError()));
C++ (Qt) QProcess *term_command = new QProcess(this); connect(term_command, SIGNAL(readyReadStandardOutput()), SLOT(command_print())); term_command->start("ping", QStringList() << "192.168.1.1"); }void MainWindow::command_print(){ QByteArray output = term_command->readAllStandardOutput(); ui->textEdit->append(output.data());}
C++ (Qt)void MainWindow::run(){ QProcess *term_command = new QProcess(this); connect(term_command, SIGNAL(readyReadStandardOutput()), SLOT(run())); term_command->start("ping", QStringList() << "192.168.1.1");} void MainWindow::finished(){ QByteArray result=term_command.readAllStandardOutput(); QStringList lines = QString(result).split("\n"); foreach (QString line, lines) { ui->textEdit->append(line); } }
C++ (Qt)class MainWindow : public QMainWindow{...private: QProcess *term_command;...}; ----MainWindow::MainWindow(QWidget *parent /*=0*/) : QMainWindow(parent){... term_command = new QProcess(this); term_command->setProcessChannelMode(QProcess::MergedChannels); connect(term_command, SIGNAL(readyReadStandardOutput()), SLOT(command_print())); term_command->start("ping", QStringList() << "192.168.1.1"); ...} void MainWindow::command_print(){ QByteArray output = term_command->readAllStandardOutput();...}
C++ (Qt)...connect(term_command, SIGNAL(processExited()), this, SLOT(exitProcess()));...void XDiagnosticTool::exitProcess(){ delete term_command; term_command = 0;}
C++ (Qt)connect(term_command,SIGNAL(finished(int,QProcess::ExitStatus)), SLOT(exitProcess()));...void XDiagnosticTool::exitProcess(){ delete term_command; term_command = 0;}
C++ (Qt)connect(term_command,SIGNAL(finished(int,QProcess::ExitStatus)), SLOT(exitProcess()));