Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. one signal(or slot) connect to multiple slot(or signal),will it lost data?
Forum Updated to NodeBB v4.3 + New Features

one signal(or slot) connect to multiple slot(or signal),will it lost data?

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 454 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    QtTester
    wrote on last edited by QtTester
    #1

    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.

    jsulmJ 1 Reply Last reply
    0
    • Q QtTester

      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.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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?

      1. No. Why should it loose data?
      2. Signals/slots across threads automatically use Qt::QueuedConnection and you should not try to change that
      3. You will not loose any data, doesn't matter whether you pass by reference or by value

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      Q 1 Reply Last reply
      0
      • jsulmJ jsulm

        @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?

        1. No. Why should it loose data?
        2. Signals/slots across threads automatically use Qt::QueuedConnection and you should not try to change that
        3. You will not loose any data, doesn't matter whether you pass by reference or by value
        Q Offline
        Q Offline
        QtTester
        wrote on last edited by
        #3

        @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?

        1. No. Why should it loose data?
        2. Signals/slots across threads automatically use Qt::QueuedConnection and you should not try to change that
        3. 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?

        jsulmJ 1 Reply Last reply
        0
        • Q QtTester

          @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?

          1. No. Why should it loose data?
          2. Signals/slots across threads automatically use Qt::QueuedConnection and you should not try to change that
          3. 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?

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by jsulm
          #4

          @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.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          Q 1 Reply Last reply
          2
          • jsulmJ jsulm

            @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.

            Q Offline
            Q Offline
            QtTester
            wrote on last edited by
            #5

            @jsulm
            R-C.png

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved