Solved 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 pointersMainWindow::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&))); } }
-
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.
-
@SGaist
and the meta system doesn't like people who lie to it ;) -
@CybeX said in Make sure 'Mat&' is registered using qRegisterMetaType(), error:
@SGaist
and the meta system doesn't like people who lie to it ;)It usually bites back :-)
-
I could solve this problem, posting below piece of code.
mainwindow.h
namespace Ui { class MainWindow; } Q_DECLARE_METATYPE(TYPEDEF) Q_DECLARE_METATYPE(TYPEDEF)
mainwindow.cpp
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); qRegisterMetaType<TYPEDEF>(); qRegisterMetaType<TYPEDEF>(); }
Replace TYPEDEF with your user defined datatypes. Hope it helps.
-
You like replying to topics that are over 3-4 years old, don't you? ;-)