I'm having problems emitting my own struct from a signal to a slot. The struct looks as following:
WorldObjectChange.h
#pragma once
struct WorldObjectChange {
WorldObjectChange() {}
~WorldObjectChange() {}
double x;
};
Q_DECLARE_METATYPE(WorldObjectChange)
I called qRegisterMetaType to make the type known in the signal slot method
main.c
QApplication a(argc, argv);
qRegisterMetaType<WorldObjectChange>();
The connection is queued since signal and slot inhabit different threads. The connect happens in the constructor of a class that initializes and starts the thread for object1.
InitClass::InitClass(Object2 *object2) {
Object1* object1 = new Object1();
connect(object1, SIGNAL(updateObjects(WorldObjectChange)), object2, SLOT(updateObjects(WorldObjectChange)));
}
object1.h
#include "WorldObjectChange.h"
class object1 : public QObject{
Q_OBJECT
public:
object1();
public signals:
void updateObjects(WorldObjectChange);
};
object2.h
#include "WorldObjectChange.h"
class object2: public QLabel {
Q_OBJECT
public:
explicit object2(QWidget * parent = 0);
public slots:
void updateObjects(WorldObjectChange worldChangeVector);
};
object2.cpp
void updateObjects(WorldObjectChange worldChangeVector) { }
The object seems to work fine in object1, but whenever I add the line for the slot in object 2 I get the following error:
Error LNK2019 unresolved external symbol "public: void __cdecl worldOutputGrid::updateObjects(struct WorldObjectChange)" (?updateObjects@worldOutputGrid@@QEAAXUWorldObjectChange@@@Z) referenced in function "private: static void __cdecl worldOutputGrid::qt_static_metacall(class QObject *,enum QMetaObject::Call,int,void * *)" (?qt_static_metacall@worldOutputGrid@@CAXPEAVQObject@@W4Call@QMetaObject@@HPEAPEAX@Z)
Thanks in advance for the help
object2::updateObjects()
a definition? – vahanchoWorldObjectChange
doesn't have members:y
,width
, orheight
. You've obviously gotta fix that to compile. If that solves your problem I can post it as an answer, but I think fixing that will help get us to the actual issues. – Jonathan Meeconnect
happening? You're not specifying the classes on theupdateObjects
so I'd assume that your signal and slot are both using either the signal or the slot's definition. – Jonathan Mee