Windows中的QProcess gpg2错误

Posted

技术标签:

【中文标题】Windows中的QProcess gpg2错误【英文标题】:QProcess gpg2 error in windows 【发布时间】:2015-10-31 14:18:02 【问题描述】:

我需要使用 Qt 使用 gpg 加密一些文本。 QCA 是别无选择。 我的函数在 Linux 中运行,但在 Windows 中我得到了 exitCode 2。

在命令行上使用相同的参数执行 gpg2.exe 会像预期的那样工作。

QString PGPProcess::encrypt(QString toAddress, QString message)


    this->start(QStringList() << "--trust-model always" << "-a" << "-e" << "-r " + toAddress);
    this->waitForStarted(PROCESS_WAIT);
    this->write(message.toUtf8());
    this->waitForBytesWritten(PROCESS_WAIT);
    this->closeWriteChannel();
    this->waitForFinished(PROCESS_WAIT);

    if(this->exitCode()) 
        qDebug() << this->exitCode();
        return message;
     else 
        return this->readAllStandardOutput();
    


我认为这与 closeWriteChannel() 有关。命令行必须发送 gpg 正在加密书面文本的 CRTL-D (Linux)。

在 Windows 中 CTRL-D 不做任何事情,我必须按 CTRL-C。 但是在 QProcess 上调用 terminate() 也不起作用。

【问题讨论】:

【参考方案1】:

好的,只需将参数 QStringList 更改为以下即可...

this->start(QStringList() << "--trust-model" << "always" << "-a" << "-e" << "-r" << toAddress);

【讨论】:

以上是关于Windows中的QProcess gpg2错误的主要内容,如果未能解决你的问题,请参考以下文章

在 Windows 错误中使用 QProcess 启动进程:“计时器只能用于以 QThread 启动的线程”

QT下的QProcess调用外部程序

带有 adb 的 QProcess 输出始终为空

Qt:无法使用 QProcess 启动 Windows 控制台

在 Windows 上向 QProcess 发送 Ctrl+C

如何在 Windows 上通过 QProcess 启动提升的子进程?