one signal(or slot) connect to multiple slot(or signal),will it lost data?
-
Hi, guys.
I have multiple camera and a class wrapper for them.
Here is my architechture:// a thread to capture camera and process data, use signal to notify manager class Thread { signals: void camSignal(QList<int> result,QImage img); } // an interface managing cameras and his threads class CamManager { public: Thread a,b,c,d,e; void bind(){ connect(&a,&Thread::camSignal,this,onCamSignal); // ... // also connect for b,c,d,e } slot: void onCamSignal(QList<int> result,QImage img){ // display...and other things // to external caller emit camSignalExternal(result,img, otherParams); } // an interface for external caller signals: void camSignalExternal(QList<int> result,QImage img,int others); }For external callers:
class Caller1 { public: CamManager *cm; void init(){ connect(cm,&CamManager:camSignalExternal,this,onCamSignal); } // receive all cameras' data slot: void onCamSignal(QList<int> result,QImage img,int others); } class Caller2 { public: // same instance to Caller1 CamManager *cm; void init(){ connect(cm,&CamManager:camSignalExternal,this,onCamSignal); } // receive all cameras' data slot: void onCamSignal(QList<int> result,QImage img,int others); }My question are:
1、data from 'class Thread' to 'class CamManager ',will the slot lost data? If it lost data, should I use connect parameter 'Qt::UniqueConnection' ?
2、data from 'class CamManager ' to 'class Caller',Qt::UniqueConnection is the best choise?
3、In there multiple signals to one slot, or one signal to multiple slots situation,
signal's parameter use &(reference) or pass value directly ,which one is better and has no risk to lost data?//Fast reference method: void camSignalExternal(const QList<int> &result,cosnt QImage &img); // .VS. copying method: void camSignalExternal(QList<int> result,QImage img);any reply will be appreciated.
-
Hi, guys.
I have multiple camera and a class wrapper for them.
Here is my architechture:// a thread to capture camera and process data, use signal to notify manager class Thread { signals: void camSignal(QList<int> result,QImage img); } // an interface managing cameras and his threads class CamManager { public: Thread a,b,c,d,e; void bind(){ connect(&a,&Thread::camSignal,this,onCamSignal); // ... // also connect for b,c,d,e } slot: void onCamSignal(QList<int> result,QImage img){ // display...and other things // to external caller emit camSignalExternal(result,img, otherParams); } // an interface for external caller signals: void camSignalExternal(QList<int> result,QImage img,int others); }For external callers:
class Caller1 { public: CamManager *cm; void init(){ connect(cm,&CamManager:camSignalExternal,this,onCamSignal); } // receive all cameras' data slot: void onCamSignal(QList<int> result,QImage img,int others); } class Caller2 { public: // same instance to Caller1 CamManager *cm; void init(){ connect(cm,&CamManager:camSignalExternal,this,onCamSignal); } // receive all cameras' data slot: void onCamSignal(QList<int> result,QImage img,int others); }My question are:
1、data from 'class Thread' to 'class CamManager ',will the slot lost data? If it lost data, should I use connect parameter 'Qt::UniqueConnection' ?
2、data from 'class CamManager ' to 'class Caller',Qt::UniqueConnection is the best choise?
3、In there multiple signals to one slot, or one signal to multiple slots situation,
signal's parameter use &(reference) or pass value directly ,which one is better and has no risk to lost data?//Fast reference method: void camSignalExternal(const QList<int> &result,cosnt QImage &img); // .VS. copying method: void camSignalExternal(QList<int> result,QImage img);any reply will be appreciated.
@QtTester said in one signal(or slot) connect to multiple slot(or signal),will it lost data?:
data from 'class Thread' to 'class CamManager ',will the slot lost data?
- No. Why should it loose data?
- Signals/slots across threads automatically use Qt::QueuedConnection and you should not try to change that
- You will not loose any data, doesn't matter whether you pass by reference or by value
-
@QtTester said in one signal(or slot) connect to multiple slot(or signal),will it lost data?:
data from 'class Thread' to 'class CamManager ',will the slot lost data?
- No. Why should it loose data?
- Signals/slots across threads automatically use Qt::QueuedConnection and you should not try to change that
- You will not loose any data, doesn't matter whether you pass by reference or by value
@jsulm said in one signal(or slot) connect to multiple slot(or signal),will it lost data?:
@QtTester said in one signal(or slot) connect to multiple slot(or signal),will it lost data?:
data from 'class Thread' to 'class CamManager ',will the slot lost data?
- No. Why should it loose data?
- Signals/slots across threads automatically use Qt::QueuedConnection and you should not try to change that
- You will not loose any data, doesn't matter whether you pass by reference or by value
Thanks for so quickly reply.
I mean Qt::QueuedConnection but type wrong :-(
So I think pass by reference will be better? -
@jsulm said in one signal(or slot) connect to multiple slot(or signal),will it lost data?:
@QtTester said in one signal(or slot) connect to multiple slot(or signal),will it lost data?:
data from 'class Thread' to 'class CamManager ',will the slot lost data?
- No. Why should it loose data?
- Signals/slots across threads automatically use Qt::QueuedConnection and you should not try to change that
- You will not loose any data, doesn't matter whether you pass by reference or by value
Thanks for so quickly reply.
I mean Qt::QueuedConnection but type wrong :-(
So I think pass by reference will be better?@QtTester said in one signal(or slot) connect to multiple slot(or signal),will it lost data?:
So I think pass by reference will be better?
Yes, use reference. But keep in mind that signal parameters are copied in case of signals/slots across thread.
-
@QtTester said in one signal(or slot) connect to multiple slot(or signal),will it lost data?:
So I think pass by reference will be better?
Yes, use reference. But keep in mind that signal parameters are copied in case of signals/slots across thread.
