简体   繁体   English

如何使用QProcess运行vim终端

[英]How to run vim terminal with QProcess

I want to do the "vim" command, The "vim" command is used to open a new editor in linux. 我想做“vim”命令,“vim”命令用于在linux中打开一个新的编辑器。 "setup.csh" open file "vi" editör with QProcess. “setup.csh”用QProcess打开文件“vi”editör。 I would like to run this command using gui. 我想用gui运行这个命令。

linux terminal command:"vim /home/intern2/elif/Project/setup.csh" .How can I run this command gui linux终端命令:“vim /home/intern2/elif/Project/setup.csh”。如何运行此命令gui

I wrote the following commands in Qt, but it did not work using QProcess. 我在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());

Unfortunately, I gave the following error message 不幸的是,我给出了以下错误消息

Error Message: 错误信息:

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

I got it working with this: 我得到了它:

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;

Don't forget to add #include <signal.h> for the kill() function. 不要忘记为kill()函数添加#include <signal.h>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM