Search code examples
c++arraysqtdata-structuressignals-slots

Qt Signals and Slots sending arrays of structures


I am looking to send data that varies in size (depending on number of tracking markers). I have a structure designed to hold all the info for one marker. This I then need to send via signals and slots to another thread to be processed. I have added the necessary meta type declarations for the structure to work. I have connected all the signals and slots properly and have everything working for one structure. However when I try to send arrays of markers the signal is not sent/recieved. Why can I only send singular instances of the structure not arrays of them, even though the structure its self contains an array??

I have tried signal and slot definitions such as:

SLOT:

void update(Datastruct output[])

and SIGNAL:

void updatemarkers(Datastruct&)

Here is my structure:

#ifndef RETURNSTRUCT_H
#define RETURNSTRUCT_H

struct Datastruct
{
    int markerid;
    double markererror;
    double markertrans[3];
    double markerrotation[3][3];

};

Q_DECLARE_METATYPE(Datastruct);

#endif //RETURNSTRUCT_H

this line was also included to avoid inferring a namespace with the type declaration.

// after QApplication was instantiated
qRegisterMetaType<Datastruct>("Datastruct");
// but before any class is instantiated that connects signals with this type

Why can I only send singular instances of the structure not arrays of them, even though the structure its self contains an array??

I am using windows 7, MinGW 32bit, Qt 5.7.0, Qt Creator 4.0.3


Solution

  • Try using Qt data structures instead of a simple array. Something like QList or QVector. They are already a metatype and can be sent by default through signals and slots. Let me know if it works.