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. Caller function ID (or something to that tune)
Forum Updated to NodeBB v4.3 + New Features

Caller function ID (or something to that tune)

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 5 Posters 1.7k 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.
  • deisikD Offline
    deisikD Offline
    deisik
    wrote on last edited by deisik
    #1

    I know this is not a Qt question but still

    I have a single instance of a class in my app (like singleton but actually declared as a global variable). Its member function gets called by instances of other classes (both different and same) in an arbitrary order through timers, and I want to distinguish between the callers, so the function would emit a signal with cashed results only if called by a new caller.

    I can easily do this via passing a parameter to the called function but I more like the sender() approach used for slots and signals, though the function is not called via a signal either directly or via another function (so sender() returns 0)

    Is it possible to do that in a simple way? I don't need function names or whatever, just a way to distinguish between the callers

    T VRoninV 2 Replies Last reply
    0
    • deisikD deisik

      I know this is not a Qt question but still

      I have a single instance of a class in my app (like singleton but actually declared as a global variable). Its member function gets called by instances of other classes (both different and same) in an arbitrary order through timers, and I want to distinguish between the callers, so the function would emit a signal with cashed results only if called by a new caller.

      I can easily do this via passing a parameter to the called function but I more like the sender() approach used for slots and signals, though the function is not called via a signal either directly or via another function (so sender() returns 0)

      Is it possible to do that in a simple way? I don't need function names or whatever, just a way to distinguish between the callers

      T Offline
      T Offline
      Tirupathi Korla
      wrote on last edited by
      #2

      @deisik
      Try passing 'this' as a parameter from calling function so that you will have object and you can assign it to Connect. Hope this helps.

      -Tirupathi

      1 Reply Last reply
      0
      • deisikD deisik

        I know this is not a Qt question but still

        I have a single instance of a class in my app (like singleton but actually declared as a global variable). Its member function gets called by instances of other classes (both different and same) in an arbitrary order through timers, and I want to distinguish between the callers, so the function would emit a signal with cashed results only if called by a new caller.

        I can easily do this via passing a parameter to the called function but I more like the sender() approach used for slots and signals, though the function is not called via a signal either directly or via another function (so sender() returns 0)

        Is it possible to do that in a simple way? I don't need function names or whatever, just a way to distinguish between the callers

        VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #3

        @deisik said in Caller function ID (or something to that tune):

        I can easily do this via passing a parameter to the called function

        That's the correct approach. "The sender() way" breaks OO principles and I would not be surprised if it was at least deprecated in Qt6

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        deisikD 1 Reply Last reply
        2
        • VRoninV VRonin

          @deisik said in Caller function ID (or something to that tune):

          I can easily do this via passing a parameter to the called function

          That's the correct approach. "The sender() way" breaks OO principles and I would not be surprised if it was at least deprecated in Qt6

          deisikD Offline
          deisikD Offline
          deisik
          wrote on last edited by deisik
          #4

          Actually, I didn't mean doing that by using the sender() option since it is not available in my case. If I'm not mistaken, you can check the stack with the backtrace() functions of execinfo.h. but it looks like a massive overkill as compared to simply passing this (or whatever) to the function directly

          Anyway, I have already worked around my problem by setting a counter in the resulting dataset which allows the callers (and their receiving slots) to decide whether the data have been updated and they actually need to process the data received. So no need to find out the caller

          jsulmJ 1 Reply Last reply
          0
          • deisikD deisik

            Actually, I didn't mean doing that by using the sender() option since it is not available in my case. If I'm not mistaken, you can check the stack with the backtrace() functions of execinfo.h. but it looks like a massive overkill as compared to simply passing this (or whatever) to the function directly

            Anyway, I have already worked around my problem by setting a counter in the resulting dataset which allows the callers (and their receiving slots) to decide whether the data have been updated and they actually need to process the data received. So no need to find out the caller

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

            @deisik said in Caller function ID (or something to that tune):

            you can check the stack with the backtrace()

            This would be like shooting a sparrow with artillery :-)

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

            1 Reply Last reply
            0
            • kkoehneK Offline
              kkoehneK Offline
              kkoehne
              Moderators
              wrote on last edited by
              #6

              QSignalMapper is deprecated, but might still be handy for your use case : https://doc.qt.io/qt-5/qsignalmapper.html

              Director R&D, The Qt Company

              1 Reply Last reply
              2

              • Login

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