如何使用QProcess

时间:2016-11-16 11:10:08

标签: c++ linux qt qprocess

我想做“vim”命令,“vim”命令用于在linux中打开一个新的编辑器。 “setup.csh”用QProcess打开文件“vi”editör。我想用gui运行这个命令。

linux terminal命令:“vim /home/intern2/elif/Project/setup.csh”。如何运行此命令gui

我在Qt中编写了以下命令,但它在使用QProcess时无效。

QProcess *process1=new QProcess(this);
process1->start("vim" , QStringList() <<"/home/intern2/elif/Project/setup.csh");
process1->waitForBytesWritten();
process1->waitForFinished();
ui->textEdit_3->append(process1->readAllStandardOutput());

不幸的是,我提供了以下错误消息

错误讯息:

Warning: Output is not a terminal
Warning: Input is not from a terminal

1 个答案:

答案 0 :(得分:0)

我得到了它的工作:

QProcess* process = new QProcess();
qint64* processId = new qint64();
process->startDetached("/usr/bin/vim", QStringList(), QString(), processId);

// Wait for process to be closed by user (kill()
// does not actually kill the process, but tests if it exists)
while (kill(*processId, 0) == 0) {}

// Done
delete processId;
delete process;

不要忘记为#include <signal.h>功能添加kill()