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. SIgnal/slots or function pointers??
Forum Updated to NodeBB v4.3 + New Features

SIgnal/slots or function pointers??

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 4 Posters 3.0k Views 1 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.
  • T Offline
    T Offline
    TagLog
    wrote on last edited by
    #1

    What are the pros and cons of the two system of linking classes or methods??

    raven-worxR 1 Reply Last reply
    0
    • T TagLog

      What are the pros and cons of the two system of linking classes or methods??

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @TagLog said in SIgnal/slots or function pointers??:

      of linking classes or methods

      what exactly do you mean by this?

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      1
      • T Offline
        T Offline
        Tikani
        wrote on last edited by
        #3

        What pros/cons of using singal-slot system instead of typical event handler system?
        It's just a different point of views to the same conception. Moreover, signal-slot system, in common case, is implemented having event handlers system under the hood, i.e. "signal-slot" is simply a kind of syntactic sugar and "events", in their turn, is a cascade of callbacks based on function pointers.
        Qt is built around MOC, it brings a powerful introspectional features in run-time and Qt's signal/slot fully utilizes it but in order to use it your class must be a descendant of QObject, it's a main and single constraint.
        It my case, for example, I use functional pointers in pure C++ classes because these ones slighly faster than QObject derivatives with metaobject overhead. But in a code with tight interactions with Qt componens I use singnal-slots, if it allows me to get what I want to implement. By the way, Qt's singnal-slot system isn't that strict, so you can bind signal with lambda, for example.
        Feel the Force, Luke.

        raven-worxR 1 Reply Last reply
        2
        • T Tikani

          What pros/cons of using singal-slot system instead of typical event handler system?
          It's just a different point of views to the same conception. Moreover, signal-slot system, in common case, is implemented having event handlers system under the hood, i.e. "signal-slot" is simply a kind of syntactic sugar and "events", in their turn, is a cascade of callbacks based on function pointers.
          Qt is built around MOC, it brings a powerful introspectional features in run-time and Qt's signal/slot fully utilizes it but in order to use it your class must be a descendant of QObject, it's a main and single constraint.
          It my case, for example, I use functional pointers in pure C++ classes because these ones slighly faster than QObject derivatives with metaobject overhead. But in a code with tight interactions with Qt componens I use singnal-slots, if it allows me to get what I want to implement. By the way, Qt's singnal-slot system isn't that strict, so you can bind signal with lambda, for example.
          Feel the Force, Luke.

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          @Tikani
          Qt's signal/slots concept isn't necessarily bound to events! Only if the invokation is triggered queued (e.g. between threads)

          One advantage is that you do not need to know the exact type of the instance. It's enough when you know it's a QObject instance. This lets the MOC abstract the whole logic.
          Whereas with function pointers you need to know the exact type to be able to call them.

          If you can live with function pointers, then go with them.

          Calling methods via the meta-object also enables the following:

          bool successfulCalled = QMetaObject::invokeMethod( onObj, "method", Qt::QueuedConnection, Q_ARG(int,arg1) );
          if( !successfulCalled )
          {
               // object doesn't have a method with such signature
          }
          

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          3
          • Arvindhan PonnusamyA Offline
            Arvindhan PonnusamyA Offline
            Arvindhan Ponnusamy
            wrote on last edited by
            #5

            SIgnal/slots by default of Qt::QueuedConnection but function pointers is Qt::DirectConnection.
            Moreover it is recommended to use Signals/Slots in multi thread affinities

            raven-worxR 1 Reply Last reply
            0
            • Arvindhan PonnusamyA Arvindhan Ponnusamy

              SIgnal/slots by default of Qt::QueuedConnection but function pointers is Qt::DirectConnection.
              Moreover it is recommended to use Signals/Slots in multi thread affinities

              raven-worxR Offline
              raven-worxR Offline
              raven-worx
              Moderators
              wrote on last edited by
              #6

              @Arvindhan-Ponnusamy said in SIgnal/slots or function pointers??:

              SIgnal/slots by default of Qt::QueuedConnection

              who says that?!
              By default Qt::AutoConnection is used. Which results in Qt::DirectConnection if sender and receiver are in the same thread, Qt::QueuedConnection otherwise.

              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
              If you have a question please use the forum so others can benefit from the solution in the future

              Arvindhan PonnusamyA 1 Reply Last reply
              3
              • raven-worxR raven-worx

                @Arvindhan-Ponnusamy said in SIgnal/slots or function pointers??:

                SIgnal/slots by default of Qt::QueuedConnection

                who says that?!
                By default Qt::AutoConnection is used. Which results in Qt::DirectConnection if sender and receiver are in the same thread, Qt::QueuedConnection otherwise.

                Arvindhan PonnusamyA Offline
                Arvindhan PonnusamyA Offline
                Arvindhan Ponnusamy
                wrote on last edited by
                #7

                @raven-worx By default Qt::AutoConnection is used. Which results in Qt::DirectConnection if sender and receiver are in the same thread, Qt::QueuedConnection otherwise.
                Yes.It is correct.
                But what i was trying to say is about multi threaded affinity.

                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