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

后端 未结 3 1131
[愿得一人]
[愿得一人] 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 ;
        });
    
    0 讨论(0)
  • 2020-12-21 01:17

    I believe the following will work:

    connect(cameraControl, SIGNAL(finished(int , QProcess::ExitStatus )), this, SLOT(on_cameraControlExit(int , QProcess::ExitStatus )));
    
    0 讨论(0)
  • 2020-12-21 01:31

    Or with C++14 (modern compilers)

    QObject::connect(cameraControl, qOverload<int, QProcess::ExitStatus >(&QProcess::finished), this, &MainWindow::on_cameraControlExit);
    

    Or in the Qt5 convention:

    QObject::connect(cameraControl, static_cast<void(QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished), this, &MainWindow::on_cameraControlExit);
    
    0 讨论(0)
提交回复
热议问题