gpt4 book ai didi

c++ - 如何使用 QProcess 运行 vim 终端

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:22:38 24 4
gpt4 key购买 nike

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

linux 终端命令:"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

最佳答案

我用它来工作:

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()功能。

关于c++ - 如何使用 QProcess 运行 vim 终端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40630639/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com