Signal emitting a structure

不羁的心 提交于 2020-01-24 13:12:08

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/15567838/signal-emitting-a-structure

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!