todayihateprogramming
todayihateprogramming

Reputation: 157

signal slot custom struct issue

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

Upvotes: 1

Views: 289

Answers (1)

Jonathan Mee
Jonathan Mee

Reputation: 38959

connect takes a QObject* as it's 1st and 3rd arguments. In your code:

connect(object1, SIGNAL(updateObjects(WorldObjectChange)), object2, SLOT(updateObjects(WorldObjectChange)));

object1 is not a QObject*. You need to use instead:

connect(&object1, SIGNAL(updateObjects(WorldObjectChange)), object2, SLOT(updateObjects(WorldObjectChange)));

Upvotes: 0

Related Questions