I need to encrypt some text with gpg using Qt. QCA is no choice. My function is working in Linux but in Windows I get exitCode 2.
Executing the gpg2.exe with the same arguments on the commandline is working like expected.
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();
}
}
I think it hast to do with closeWriteChannel(). Commandline has to send CRTL-D (Linux) that gpg is encrypting the written text.
In Windows CTRL-D does not do anything, there I have to press CTRL-C. But calling terminate() on the QProcess does not work too.