Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Make sure 'Mat&' is registered using qRegisterMetaType(), error

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

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 5 Posters 9.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • mandruk1331M Offline
    mandruk1331M Offline
    mandruk1331
    wrote on last edited by mandruk1331
    #1

    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

    mandruk1331M 1 Reply Last reply
    0
    • mandruk1331M mandruk1331

      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&)));
          }
      }
      
      mandruk1331M Offline
      mandruk1331M Offline
      mandruk1331
      wrote on last edited by
      #2

      @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&)));
          }
      }
      

      Mandruk1331

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        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.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        CybeXC 1 Reply Last reply
        2
        • SGaistS SGaist

          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.

          CybeXC Offline
          CybeXC Offline
          CybeX
          wrote on last edited by
          #4

          @SGaist
          and the meta system doesn't like people who lie to it ;)

          SGaistS 1 Reply Last reply
          0
          • CybeXC CybeX

            @SGaist
            and the meta system doesn't like people who lie to it ;)

            SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @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 :-)

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • R Offline
              R Offline
              RahulM44
              wrote on last edited by
              #6

              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.

              Pl45m4P 1 Reply Last reply
              -1
              • R RahulM44

                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.

                Pl45m4P Offline
                Pl45m4P Offline
                Pl45m4
                wrote on last edited by
                #7

                @RahulM44

                You like replying to topics that are over 3-4 years old, don't you? ;-)


                If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                ~E. W. Dijkstra

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved