Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. How to emit a signal in whole of project?
Forum Updated to NodeBB v4.3 + New Features

How to emit a signal in whole of project?

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
qsocketnotifieremit signal
5 Posts 4 Posters 7.2k Views 2 Watching
  • 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.
  • M Offline
    M Offline
    MhM93
    wrote on 7 Jun 2016, 04:23 last edited by
    #1

    Hi.
    I receive data from QSocketNotifier in mainwindow.cpp . I want to emit signal when receive data in whole of application.
    Then each class that they need this signal, call their own slot to do something.
    How to define a global signal that work in whole of project?

    H.Ghassami

    1 Reply Last reply
    0
    • M Offline
      M Offline
      micland
      wrote on 7 Jun 2016, 09:42 last edited by
      #2

      There is no "broadcast" mechanism to send a signal to every object. You have to connect every slot explicitely.
      So you have to make your QSoketNotifier global accessible and every object can access the instance and connect to the signal himself if wanted.
      (That's possible but not a clean solution - you should try to rework your code so that the signal emitting object does not need to know the receivers and the signal receiving objects do not need to know the emitter and some glue code initializes all instances and connects the signals and slots).

      1 Reply Last reply
      1
      • H Offline
        H Offline
        Hamed.Masafi
        wrote on 7 Jun 2016, 13:15 last edited by
        #3

        Create a class with singleton and observer pattern.

        Remote object sharing (OO RPC)
        http://forum.qt.io/topic/60680/remote-object-sharing-oo-rpc-solved

        Advanced, Powerful and easy to use ORM for Qt5
        https://forum.qt.io/topic/67417/advanced-powerful-and-easy-to-use-orm-for-qt5

        K 1 Reply Last reply 7 Jun 2016, 23:12
        1
        • H Hamed.Masafi
          7 Jun 2016, 13:15

          Create a class with singleton and observer pattern.

          K Offline
          K Offline
          kshegunov
          Moderators
          wrote on 7 Jun 2016, 23:12 last edited by kshegunov 6 Jul 2016, 23:14
          #4

          @MhM93

          Hello,
          @micland Has provided some good points. I think however that the cleanest solution to a problem like this is to delegate the signals through the object hierarchy (and not to expose the original emitter to every object). So every parent object will have a signal, that the children will subscribe to, which in turn will raise the child's signal and so on.
          For (a simple) example:

          class PropagatingSignalClass : public QObject
          {
              Q_OBJECT
          public:
              PropagatingSignalClass(QObject * parent)
                  : QObject(parent)
              {
                  PropagatingSignalClass * interestingParent = qobject_cast<PropagatingSignalClass *>(parent);
                  if (interestingParent)
                      QObject::connect(interestingParent, SIGNAL(someInterestingSignal()), this, SIGNAL(someInterestingSignal()));
              }
          
          signals:
              void someInterestingSignal();
          }
          

          When the top-level QObject's signal is triggered such structure will carry the signal down the object tree and isn't too hard to implement.

          Kind regards.


          @Hamed.Masafi

          Create a class with singleton and observer pattern.

          Why should he do that exactly? By the way a slot (connected to a signal) is already an observer pattern.

          Read and abide by the Qt Code of Conduct

          1 Reply Last reply
          1
          • M Offline
            M Offline
            MhM93
            wrote on 8 Jun 2016, 05:03 last edited by
            #5

            Thanks for all. I should test it , if it works I will put the code completely here.

            H.Ghassami

            1 Reply Last reply
            0

            5/5

            8 Jun 2016, 05:03

            • Login

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