Pregunta

En resumen, me sale de siguiente error:

QObject::connect: Cannot queue arguments of type 'cv::Mat'
(Make sure 'cv::Mat' is registered using qRegisterMetaType().)

Lo que estoy tratando de hacer es enviar una señal que contiene dos imágenes CV :: Mat de un QThread al hilo principal, para que pueda mostrar la salida. No hay un error de tiempo de compilación, pero cuando ejecuto el programa, se atasca en un punto de interrupción en qglobal.h (inline void qt_noop() {}).

He intentado agregar Q_DECLARE_METATYPE(cv::Mat) al código, en vano. Estoy bastante chupando con qué hacer ahora.

Código

en una clase QThread:

signals:
void sndFlow(cv::Mat &leftEye, cv::Mat &rightEye);

void eyesDriver::run()
{
    forever
    {
        flow->draw(leftEye, rightEye);
        sndFlow(leftEye, rightEye);
    }
}

Capturando en una clase QObject:

public slots:
void recFlow(cv::Mat &leftEye, cv::Mat &rightEye);

void myClass::recFlow(cv::Mat &leftEye, cv::Mat &rightEye)
{
    cv::imshow("left", leftEye);
    cv::imshow("rigth", rightEye);
    cv::waitKey(40);
}

en la principal:

Q_DECLARE_METATYPE(cv::Mat)
int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    qRegisterMetaType< cv::Mat >("cv::Mat");
    // create objects from QThread and QObject class
    QObject::connect(&qthread, SIGNAL(sndFlow(cv::Mat&,cv::Mat&)),
                     &qobject, SLOT(recFlow(cv::Mat&,cv::Mat&)));
    qthread.start();
    return a.exec();
}

Cambiar las variables de ranura de señal a QSharedPointer< cv::Mat > tampoco funciona. Da el mismo error:

QObject::connect: Cannot queue arguments of type 'QSharedPointer<cv::Mat>'
(Make sure 'QSharedPointer<cv::Mat>' is registered using qRegisterMetaType().)

Funciona

De acuerdo, parece funcionar. He movido qRegisterMetaType< cv::Mat >("cv::Mat"); justo antes de la llamada QObject::connect. Sin embargo, todavía tengo que "f5" más allá del punto de interrupción en Qglobal.h, funciona después.

Podría estar equivocado, pero parece que la ubicación del qRegisterMetaType no es trivial.

¿Fue útil?

Solución

You need to call qRegisterMetaType in addition to the macro (or instead of it, depending on your needs). This is necessary for the signals to be able to marshal your data across threads. However, it might be a wiser idea to pass by reference or smart pointer, or raw pointer if you are using the QObject hierarchy to manage the object lifetime.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top