Qt没有这样的槽为QProcess :: finished()信号 [英] Qt No such slot for the QProcess::finished() signal

查看:3110
本文介绍了Qt没有这样的槽为QProcess :: finished()信号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从我在Linux中运行的Qt应用程序运行命令行程序gphoto2,并读取其输出到标准输出和标准错误的结果。此概念验证程序中的GUI是单个按钮和用于显示标准错误和标准输出的输出的标签。



我遇到问题将QtProcess :: Finished信号连接到正确的插槽。我从Finished()信号文档中的头,连接语句和函数复制了参数列表。函数名称以MainWindow ::类标识符为前缀。我已经用尽了尝试,我希望有人在StackOverflow将能够指出的问题。

 标头档案:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include< QMainWindow>
#include< QString>
#include< QProcess>
#include< QObject>

namespace Ui {
class MainWindow;
}

class MainWindow:public QMainWindow
{
Q_OBJECT

public:
explicit MainWindow(QWidget * parent = 0 );
〜MainWindow();
void reply2();


私有插槽:
void on_pushButton_clicked();
void on_cameraControlExit(int exitCode,QProcess :: ExitStatus exitStatus);


private:
Ui :: MainWindow * ui;
QProcess * cameraControl;

};

#endif // MAINWINDOW_H

mainwindow.cpp文件

  #includemainwindow.h
#includeui_mainwindow.h
#include< QProcess>
#include< QShortcut>
#include< QDebug>



MainWindow :: MainWindow(QWidget * parent):
QMainWindow(parent),
ui(new Ui :: MainWindow)
{
ui-> setupUi(this);
cameraControl = new QProcess(this);

}

MainWindow ::〜MainWindow()
{
delete ui;
cameraControl-> close();
delete cameraControl;
}


void MainWindow :: on_pushButton_clicked()
{
//将摄像机控制完成信号连接到将读取退出代码的插槽和
//将进程的std输出字符串放在
连接上的标签中(cameraControl,SIGNAL(finished,intProcess,ExitStatus)),
this,SLOT MainWindow :: on_cameraControlExit(int exitCode,QProcess :: ExitStatus exitStatus)));

//禁用ui按钮,我们不会得到双击
ui-> pushButton-> setDisabled(true);

//设置gphoto2参数列表
QStringList args;
args.append( - capture-image-and-download);

//启动摄像机控制
cameraControl-> start(gphoto2,args);

// //等待进程完成或30秒(以先到者为准)
cameraControl-> waitForFinished(30000);

}



void MainWindow :: on_cameraControlExit(int exitCode,QProcess :: ExitStatus exitStatus)
{
qDebug ()<< cameraControl-> errorString();
qDebug()<< cameraControl-> readAllStandardError();
qDebug()<< cameraControl-> readAllStandardOutput();




ui-> pushButton-> setEnabled(true);

}


解决方案以下将工作:

 
connect(cameraControl,SIGNAL(finished,intProcess,ExitStatus)),this,SLOT(on_cameraControlExit int,QProcess :: ExitStatus)));


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 this proof of concept program is a single push button and a label that is used to display the output from Standard Error and Standard output.

I'm having trouble connecting the QtProcess::Finished signal to the correct slot. I copied the arguments list from the Finished() signal documentation in the header, the connect statement, and the function. The function name is prefixed with the MainWindow:: class identifier. I've run out of things to try and I'm hoping someone in StackOverflow will be able to point out the problem.

The Header file:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QString>
#include <QProcess>
#include <QObject>

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
    void reply2();


private slots:
    void on_pushButton_clicked();
    void on_cameraControlExit(int exitCode, QProcess::ExitStatus exitStatus);


private:
    Ui::MainWindow *ui;
    QProcess* cameraControl;

};

#endif // MAINWINDOW_H

The mainwindow.cpp file

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QProcess>
#include <QShortcut>
#include <QDebug>



MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
     cameraControl = new QProcess(this);

}

MainWindow::~MainWindow()
{
    delete ui;
    cameraControl->close();
    delete cameraControl;
}


void MainWindow::on_pushButton_clicked()
{
    // connect the camera control finished signal to the slot that will read the exit code and
    // place the std output string from the process into a label on the form
    connect(cameraControl, SIGNAL(finished(int , QProcess::ExitStatus )),
            this, SLOT(MainWindow::on_cameraControlExit(int exitCode, QProcess::ExitStatus exitStatus)));

    // Disable the ui button do we don't get double presses
    ui->pushButton->setDisabled(true);

    // setup the gphoto2 arguments list
    QStringList args;      
    args.append("--capture-image-and-download");

    // start the camera control
    cameraControl->start("gphoto2",args);

//    // wait for the process to finish or 30 seconds whichever comes first
    cameraControl->waitForFinished(30000);

}



void MainWindow::on_cameraControlExit(int exitCode, QProcess::ExitStatus exitStatus)
{
    qDebug() << cameraControl->errorString();
    qDebug() << cameraControl->readAllStandardError();
    qDebug() << cameraControl->readAllStandardOutput();




    ui->pushButton->setEnabled(true);

}

解决方案

I believe the following will work:

connect(cameraControl, SIGNAL(finished(int , QProcess::ExitStatus )), this, SLOT(on_cameraControlExit(int , QProcess::ExitStatus )));

这篇关于Qt没有这样的槽为QProcess :: finished()信号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆