Run Windows .exe in Qt application

The task was to write a Qt Quick application (GUI) to upload new firmware to a touch controller.
The upload software was provided by the manufacturer in a .exe application that loads a .bin file onto the touch controller.
I wanted to use the Qt classes "QProcess", which can be used to call and control shell applications. On the Linux side, I had already used this successfully several times - but on Windows it didn't work at first.


The "trick" or solution for this was to use "setWorkingDirectory". Here is an excerpt from the .h and .cpp files. Please note the line "process->setWorkingDirectory..." in the .cpp file.


#include <QObject>
#include <QtQuick>
#include <QDebug>
#include <QProcess>
#include <QVariant>
#include <QString>
#include <QDir>

class CmdLauncher : public QProcess

    CmdLauncher(QObject *parent = nullptr);

    Q_INVOKABLE void start(const QString &program, const QVariantList &arguments);

    QString application_directory;



#include "cmdlauncher.h"

CmdLauncher::CmdLauncher(QObject *parent) : QProcess(parent)
    process_running = "start";

void CmdLauncher::start(const QString &program, const QVariantList &arguments) {
    QStringList args;

    // convert QVariantList from QML to QStringList for QProcess/
    for (int i = 0; i < arguments.length(); i++)
        args << arguments[i].toString();

    // start request or upload process
    QProcess * process = new QProcess();
    process->setWorkingDirectory(application_directory + "/nConsoleTool");
    process->start(program, args);

    // get values and set states
    QByteArray bytes = process->readAll();
    cmd_output = QString::fromLocal8Bit(bytes);
    emit cmdOutputChanged();


import QtQuick 2.9
import QtQuick.Window 2.3
import QtQuick.Controls 2.5
import QtQuick.Dialogs 1.2
import QtQuick.Layouts 1.3
import CmdLauncher 1.0

ApplicationWindow {
    id: application_window
    visible: true
    width: 1024
    height: 768
    title: qsTr("Firmware Tool")

    CmdLauncher {
        id: launcher

    Button {
        id: nUpdateFW
        x: 260
        y: 20
        width: 200
        height: 30
        text: "Upload Firmware"

        onClicked: {
            //console.log(launcher.application_directory + "/nConsoleTool/nUpdateFW.exe");
            if (file_path == "") {
            } else {
                launcher.start(launcher.application_directory + "/nConsoleTool/nUpdateFW.exe", [ file_path, "-ba" ]);
                if (launcher.controller_detected == false) {