Make sure 'Mat&' is registered using qRegisterMetaType(), error



  • I have a class that calls Camera, and I want to create every camera dynamically, but when I do it I get this(title) error, how I can solve it? Evey Camera object starts in a new Qthread
    cameras - A vector of Camera pointers

    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
        ui->FirstDisplayLabel->setSizePolicy( QSizePolicy::Ignored, QSizePolicy::Ignored );
        for(int i=0;i<_Camera::getStaticCameraNum();i++){
            cameras.push_back(new _Camera("Camera_"+QString::number(i)));
            qRegisterMetaType<cv::Mat>("cv::Mat");
            connect(cameras.at(i),SIGNAL(sendFrame(Mat&)),this,SLOT(Display1Stream(Mat&)));
        }
    }
    


  • @mandruk1331
    The Solution:

    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
        ui->FirstDisplayLabel->setSizePolicy( QSizePolicy::Ignored, QSizePolicy::Ignored );
        for(int i=0;i<_Camera::getStaticCameraNum();i++){
            cameras.push_back(new _Camera("Camera_"+QString::number(i)));
            typedef Mat mat;
            qRegisterMetaType<mat>("Mat&");
            connect(cameras.at(i),SIGNAL(sendFrame(Mat&)),this,SLOT(Display1Stream(Mat&)));
        }
    }
    

  • Lifetime Qt Champion

    Hi,

    There's no need to call qRegisterMetaType that many times, once is enough. There's also no need for that typedef, it only makes the code less readable.

    Note that you are technically lying to the meta type system.

    Did you also check the Q_DECLARE_METATYPE macro ?

    You should declare and register the types properly, lying to qRegisterMetaType will get you in trouble in the long run.


Log in to reply