没有On_actionCapture_triggered的匹配信号

时间:2015-03-30 21:06:15

标签: c++ qt opencv face-detection

我正试图在屏幕上显示来自将显示检测到的脸部的相机的实时馈送。但是我一直得到:

QMetaObject::connectSlotsByName: No matching signal for On_actionCapture_triggered()

我已使用GUI链接任何插槽或信号进行编码。我不明白问题所在。

程序运行,然后在应用程序输出框中显示错误。

对于问题所在的任何见解都将受到赞赏。

.h文件是

#ifndef DIALOG_H
#define DIALOG_H

#include <QDialog>
#include <opencv/cv.h>
#include <opencv/highgui.h>


namespace Ui {
class Dialog;
}

class Dialog : public QDialog
{
    Q_OBJECT

public:
    explicit Dialog(QWidget *parent = 0);
    ~Dialog();

private slots:
    void on_actionCapture_triggered();

private:
    Ui::Dialog* _ui;
    CvCapture*      _capture;
    IplImage*       _img;
    CvHaarClassifierCascade* _cascade;
    CvMemStorage*   _storage;
    QList<CvScalar>  _colors;
    QPixmap*         _pixmap;
    QTimer*          _timer;

};

cpp文件是:

#endif // DIALOG_H

#include "dialog.h"
#include "ui_dialog.h"
#include "opencv/cv.h"
#include "opencv/highgui.h"
#include "opencv/cvaux.h"

#include <QTimer>


Dialog::Dialog(QWidget *parent) :
QDialog(parent),
_ui(new Ui::Dialog)
{
    _ui->setupUi(this);
    _capture = cvCaptureFromCAM( 0 );
    _cascade = (CvHaarClassifierCascade*)cvLoad("haarcascade_frontalface_alt2.xml");
    _storage = cvCreateMemStorage(0);

    _colors << cvScalar(0.0,0.0,255.0) << cvScalar(0.0,128.0,255.0)
            << cvScalar(0.0,255.0,255.0) << cvScalar(0.0,255.0,0.0)
            << cvScalar(255.0,128.0,0.0) << cvScalar(255.0,255.0,0.0)
            << cvScalar(255.0,0.0,0.0) << cvScalar(255.0,0.0,255.0);

    _timer = new QTimer(this);
    connect(_timer, SIGNAL(timeout()), this, SLOT(on_actionCapture_triggered()));
    _timer->start(10);
}

Dialog::~Dialog()
{
    cvReleaseImage(&_img);
    cvReleaseCapture(&_capture);
    delete _ui;
}

void Dialog::on_actionCapture_triggered()
{
    // Query camera for next frame
    _img = cvQueryFrame( _capture );

    if (_img)
    {
        // Detect objects
        cvClearMemStorage( _storage );

        CvSeq* objects = cvHaarDetectObjects(_img,
                                         _cascade,
                                         _storage,
                                         1.1,
                                         3,
                                         CV_HAAR_DO_CANNY_PRUNING,
                                         cvSize( 100, 100 ));

        int n = (objects ? objects->total : 0);

        CvRect* r;
        // Loop through objects and draw boxes
        for( int i = 0; i < n; i++ )
        {
            r = ( CvRect* )cvGetSeqElem( objects, i );
            cvRectangle( _img,
                         cvPoint( r->x, r->y ),
                         cvPoint( r->x + r->width, r->y + r->height ),
                         _colors[i%8]
                        );
        }

        // Convert IplImage to QImage
        QImage image = QImage((const uchar *)_img->imageData,
                              _img->width,
                              _img->height,
                              QImage::Format_RGB888).rgbSwapped();
        _pixmap = new QPixmap(QPixmap::fromImage(image));
        _ui->labelCapture->setPixmap(*_pixmap);
    }
}

1 个答案:

答案 0 :(得分:0)

Qt autoconnect mechanism尝试将信号连接到对象的插槽,形式为:

void on_<object name>_<signal name>(<signal parameters>);

所以在这里它试图找到一个名为actionCapture的对象,该对象有一个名为triggered的信号,用于将其连接到您的插槽。但是没有这样的事情它会输出那个警告。

您应该将插槽名称更改为其他名称,以避免出现此警告。