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. How to implement method, that receives object and slot of any given class?
Forum Updated to NodeBB v4.3 + New Features

How to implement method, that receives object and slot of any given class?

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 364 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.
  • A Offline
    A Offline
    Amir Afendin
    wrote on last edited by Amir Afendin
    #1

    Inside my class I'd like to implement such method that receives object and slot of any given class and makes connection for that slot. For example:

    void Emitter::emitToSlot(receiver, Receiver::slot)
    {
        connect(this, &Emitter::signal, receiver, slot);
    }
    
    Emitter myEmitter;
    Receiver myReceiver;
    myEmitter.emitToSlot(&myReceiver, &Receiver::mySlot);
    

    I tried something like this:

    template<typename Func2>
    void Emitter::emitToSlot(const typename QtPrivate::FunctionPointer<Func2>::Object *receiver, Func2 slot)
    

    but this method only works inside Emitter class for Emitter slots.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      Amir Afendin
      wrote on last edited by Amir Afendin
      #5

      Just moved definition in header file and it worked.

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

        Why do you want to do this? It's basically just a wrapper around QObject::connect().

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

        A 1 Reply Last reply
        2
        • Christian EhrlicherC Christian Ehrlicher

          Why do you want to do this? It's basically just a wrapper around QObject::connect().

          A Offline
          A Offline
          Amir Afendin
          wrote on last edited by
          #3

          @Christian-Ehrlicher said in How to implement method, that receives object and slot of any given class?:

          Why do you want to do this? It's basically just a wrapper around QObject::connect().

          Let's say I have my reasons. Although I understand that it looks strange.

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

            Then you have to reimplement what QObject::connect() does.

            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
            • A Offline
              A Offline
              Amir Afendin
              wrote on last edited by Amir Afendin
              #5

              Just moved definition in header file and it worked.

              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