Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QProcess emit exit signal too earlier



  • Hi ! I'm stuck because my process emit a exit signal but my external .exe its already running...
    that's apeared about 1 of 2 time.
    I'm on win10 64bits 8Go ram. I see that don't proc on win8 but I need do this on W10.
    Someone have an idee to fix that ?
    thanks.
    (sorry for my bad english)


  • Lifetime Qt Champion

    @Wapiti Please explain better. What process do you mean? Do you start an executable using QProcess? Please show your code.



  • hum okay sorry.

    QString launcher = "C:/Program Files/D-BOX/Gaming/Assetto Corsa/ACWithLiveMotion.exe";
    QProcess process;
    connect(&process, SIGNAL(finished(int , QProcess::ExitStatus )), this, SLOT(SessionFinish()));
    process.start(launcher, QStringList());
    
    void MainWindow::SessionFinish() {
        qDebug() << "session is finish";
    }
    

    this function is called sometimes before my exe is finish


  • Lifetime Qt Champion

    @Wapiti said in QProcess emit exit signal too earlier:

    QString launcher = "C:/Program Files/D-BOX/Gaming/Assetto Corsa/ACWithLiveMotion.exe";
    QProcess process;
    connect(&process, SIGNAL(finished(int , QProcess::ExitStatus )), this, SLOT(SessionFinish()));
    process.start(launcher, QStringList());

    Where is this code located? process looks like a local variable.
    You should also connect a slot to https://doc.qt.io/qt-5/qprocess.html#errorOccurred to see whether there is any error.



  • @jsulm
    my process is declared in my .h and initialised in the construtor like this:

    MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent)
        , ui(new Ui::MainWindow)
        , socket(new QTcpSocket(this))
        , process(new QProcess(this))
        , isRunning(false)
        , toRestart(false)
    
    {
    

    I already check that, I retry but this connect return :
    0
    QProcess::NormalExit


  • Lifetime Qt Champion

    @Wapiti I don't kow what ACWithLiveMotion.exe is doing, but maybe it spawns another process and terminates? Try to start something else via QProcess and see whether you have same issue or not.



  • @jsulm
    It's an app who launch the game Assetto Corsa who's launch by steam with parametter for using material of simulation. I think its a cause of steam execution for launch game where is locate the problem but idk .. sometime it's works succesfully.

    I'm using an other process at an other place and it's works so it's this exe I guess



  • @Wapiti
    It seems likely/possible to me that the .exe merely sets off the game running, but does not wait till it exits?



  • @Wapiti said in QProcess emit exit signal too earlier:

    QString launcher = "C:/Program Files/D-BOX/Gaming/Assetto Corsa/ACWithLiveMotion.exe";
    QProcess process;
    connect(&process, SIGNAL(finished(int , QProcess::ExitStatus )), this, SLOT(SessionFinish()));
    process.start(launcher, QStringList());

    void MainWindow::SessionFinish() {
    qDebug() << "session is finish";
    }

    Are you sure that you did not use local variable?
    if process is defined in the header, the connection should look like this?
    connect(process, SIGNAL(finished(int , QProcess::ExitStatus )), this, SLOT(SessionFinish()));


Log in to reply