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. sender null on functor receiver of connect(const QObject *sender, PointerToMemberFunction signal, Functor functor) ? :'(
Forum Updated to NodeBB v4.3 + New Features

sender null on functor receiver of connect(const QObject *sender, PointerToMemberFunction signal, Functor functor) ? :'(

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 962 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.
  • M Offline
    M Offline
    mbruel31
    wrote on last edited by
    #1

    Hi,
    I'm doing this kind of connection connect(this, &ScopedSignal::scopedSignalReply, m_receivingSlot);
    with m_receivingSlot being of type: std::function<void()>
    initialized with: std::bind(&NotificationList::onNotificationsReadReply, this)

    and my receiving slot:

    void NotificationList::onNotificationsReadReply()
    {
        QObject * s = sender();
    ...
    }
    
    

    My sender is null :(
    I need it as it is the key of a Map where I should delete the associated service...
    Any idea?

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Then use a simple lambda function

      connect(this, &ScopedSignal::scopedSignalReply, this, [this]() { onNotificationsReadReply(this); }
      

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      4
      • M Offline
        M Offline
        mbruel31
        wrote on last edited by
        #3

        @Christian-Ehrlicher great this does the job perfectly! \o/ I've extra parameters in my lambda but that a great workaround.
        I still would like to understand why the sender is null.
        I've never checked the underlying code of functor connection but I would expect it should be able to retrieve the sender...
        Anybody else had this issue?
        Is it something specific to the functor signature that is processed just like a C callback maybe?
        Interesting to know about no?

        JonBJ Christian EhrlicherC 2 Replies Last reply
        0
        • M mbruel31

          @Christian-Ehrlicher great this does the job perfectly! \o/ I've extra parameters in my lambda but that a great workaround.
          I still would like to understand why the sender is null.
          I've never checked the underlying code of functor connection but I would expect it should be able to retrieve the sender...
          Anybody else had this issue?
          Is it something specific to the functor signature that is processed just like a C callback maybe?
          Interesting to know about no?

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @mbruel31
          Because sometimes QObject::sender() is not set/invalid. In any case, it was first obsoleted by QSignalMapper and now by lambdas.

          1 Reply Last reply
          0
          • M mbruel31

            @Christian-Ehrlicher great this does the job perfectly! \o/ I've extra parameters in my lambda but that a great workaround.
            I still would like to understand why the sender is null.
            I've never checked the underlying code of functor connection but I would expect it should be able to retrieve the sender...
            Anybody else had this issue?
            Is it something specific to the functor signature that is processed just like a C callback maybe?
            Interesting to know about no?

            Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @mbruel31 said in sender null on functor receiver of connect(const QObject *sender, PointerToMemberFunction signal, Functor functor) ? :'(:

            Is it something specific to the functor signature that is processed just like a C callback maybe?

            To few information - it can be e.q. a QueuedConnection due to thread context switch or similar.

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mbruel31
              wrote on last edited by
              #6

              hum didn't know QSignalMapper..
              well same thread, direct connection, that's why I don't understand...
              anyway, not an issue, I can use lambda :)

              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