Qt No such slot for the QProcess::finished() signal

后端 未结 3 1160
[愿得一人]
[愿得一人] 2020-12-21 00:27

I am trying to run a command line program, gphoto2 from my Qt app running in Linux and read the results that it outputs to Standard Output and Standard Error. The GUI in th

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-21 01:08

    I had the same issue. I think it happens because finished signal function is overloaded with 2 signatures and the compiler has trouble to infer the type:

    void finished(int exitCode); 
    void finished(int exitCode, QProcess::ExitStatus exitStatus);
    

    Here is my quick-and-dirty workaround:

    1) Open qprocess.h

    2) Comment the "shorter" signatures:

    //  void finished(int exitCode); 
    

    3) Then connect finished-signal with your lambda slot:

     QObject::connect(&process, &QProcess::finished, [=](int exitCode, QProcess::ExitStatus exitStatus){
           qDebug() << "finished. Exit code: " + exitCode ;
        });
    

提交回复
热议问题