c++ - On_actionCapture_triggered 没有匹配信号

标签 c++ qt opencv face-detection

我正在尝试在屏幕上显示来自摄像头的实时画面,该画面会显示检测到的面孔。但是我不断得到:

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

我没有使用 GUI 来链接任何插槽或信号,而是对此进行了编码。我不明白问题出在哪里。

程序运行后在Application输出框中显示错误。

任何有关问题所在的见解都将不胜感激。

.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);
    }
}

最佳答案

Qt autoconnect mechanism尝试以以下形式将信号连接到对象槽:

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

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

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

关于c++ - On_actionCapture_triggered 没有匹配信号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29356283/

相关文章:

python - opencv warpPerspective参数计数

opencv - 如何将表示具有 40 个波段的图像的数组保存到 .tif 文件

c++ - 结构体用malloc分配,为什么? C++代码分析

c++ - 跨平台 C++ 动态库插件加载器

c++ - 这个使用 decltype 和 declval 的 C++ typedef 应该如何编写以使其可移植?

qt - 引用 QML 单例类实例?

python - 在 OSX 10.6.8 上安装 PySide

c++ - 动态依赖 lib/tls 搜索路径

c++ - QPushbutton 中可能存在错误?

python-3.x - Python图像连接