2

This question is in my mind for many days but i got cleared till now

if i try to send a signal of a structure say

struct radarStruct
{
    unsigned char *Data;
    unsigned int rate;
    unsigned int timeStamp;
    float timeSec;
};

shall i emit the signal like

signals:
    void radarGeneratorData(const radarStruct &);

or

signals:
    void radarGeneratorData(radarStruct *);

More: what about the unsigned char *Data , whether the signal will make a deep copy of it ??

similar for a unsigned char *data how i can send the signal .

Friends please help me clear this , the best way to send a structure through signals & slot mechanism ..

Thnks in advance

Wagmare
  • 1,354
  • 1
  • 24
  • 58
  • Check this answer: http://stackoverflow.com/questions/39495926/qt-signal-slots-sending-a-complete-structure/42875402#42875402 – JaRo Mar 18 '17 at 14:50

1 Answers1

4

This mainly depends on your requirement.

If you want to send the structure over to another object and "share" the structure, you would need to send the structure as a pointer so that changes are reflected at source. If not then you would want to send it as a const ref.

For either methods remember you need to Q_DECLARE_METATYPE(YourStructType) before you can use the structure in signal / slot arguments.

As for when a deep copy occurs / when a routine call back equivalent process happens, you can have a read through

Signaling failure in qt slots

Single Thread communication and Cross-Threaded communication differ within themselves and the output would again depend on your usage.

Community
  • 1
  • 1
Viv
  • 17,170
  • 4
  • 51
  • 71