Important: Please read the Qt Code of Conduct -

execute enc command from QtProgram

  • Hi guys, I have the following question, I want to encrypt a file with openssl, but it doesn't give me any result, I get the message that it was encrypted, but in the Qt output panel, I get an invalid command.
    Any suggestion of how I could do it would be appreciated, I am using QProcess and Openssl 1.1 for it, below I leave the code, thanks in advance.


    #include "mainwindow.h"
    #include "./ui_mainwindow.h"
    #include <QProcess>
    #include <QMessageBox>
    MainWindow::MainWindow(QWidget *parent)
      : QMainWindow(parent), ui(new Ui::MainWindow)
      delete ui;
    void MainWindow::on_pushButton_clicked()
      QProcess *proc=new QProcess(this);
      QStringList argv;
      argv.append(" enc -des-cbc -a -in C:/Users/Lincoln/Desktop/test.txt -pass pass:123");
      argv.append(" -out C:/Users/Lincoln/Desktop/test.enc");
      bool res=proc->startDetached("D:/OpenSSL-Win64/bin/openssl.exe",argv);
        QMessageBox::information(this,qApp->applicationName(),"Archivo encriptado");
        QMessageBox::critical(this,qApp->applicationName(),"Hubo un error");


    Note that I get an encrypted file, but below it says something else.

  • Lifetime Qt Champion

    You construct the argv incorrectly so its tries to run enc as an app and that fails.
    Each parameter should be added on its own like.

    QStringList arguments;
    arguments << "enc" << "-des-cbc" << "-a" and so on;

  • great, i fixed it, thanks man.

Log in to reply