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. Connect a signal to any function?
Forum Updated to NodeBB v4.3 + New Features

Connect a signal to any function?

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 242 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.
  • D Offline
    D Offline
    Dan203
    wrote on last edited by
    #1

    I'm playing with slots/signals. (I'm still learning) I wanted to connect a signal from my own custom object to the maximum value parameter of a QSpinBox. According to the documentation there is no slot for setMaximum on a QSpinBox. But just as a test I tried connecting my signal to the standard, non-slot, setMaximum function of the QSpinBox and it still works.

    Is this legal? Is there any reason I shouldn't do this?

    KroMignonK 1 Reply Last reply
    0
    • D Dan203

      I'm playing with slots/signals. (I'm still learning) I wanted to connect a signal from my own custom object to the maximum value parameter of a QSpinBox. According to the documentation there is no slot for setMaximum on a QSpinBox. But just as a test I tried connecting my signal to the standard, non-slot, setMaximum function of the QSpinBox and it still works.

      Is this legal? Is there any reason I shouldn't do this?

      KroMignonK Offline
      KroMignonK Offline
      KroMignon
      wrote on last edited by
      #2

      @Dan203 said in Connect a signal to any function?:

      Is this legal?

      Yes

      Is there any reason I shouldn't do this?

      No

      Now more verbose reply, there are many options to connect a signal. You can connect a signal to:

      • a slot ==> connect(src, SIGNAL(...), dest, SLOT())
      • another signal (for example relaying it) ==> connect(src, SIGNAL(...), dest, SIGNAL())
      • to a member function of a class ==> connect(src, &SrcClass::signalName, dest, &DestClass::functionName)
      • to a functor/lamba ==> connect(src, &SrcClass::signalName, { qDebug() << "signal received"; })

      take a look at https://doc.qt.io/qt-5/signalsandslots.html for more details.

      It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

      D 1 Reply Last reply
      2
      • KroMignonK KroMignon

        @Dan203 said in Connect a signal to any function?:

        Is this legal?

        Yes

        Is there any reason I shouldn't do this?

        No

        Now more verbose reply, there are many options to connect a signal. You can connect a signal to:

        • a slot ==> connect(src, SIGNAL(...), dest, SLOT())
        • another signal (for example relaying it) ==> connect(src, SIGNAL(...), dest, SIGNAL())
        • to a member function of a class ==> connect(src, &SrcClass::signalName, dest, &DestClass::functionName)
        • to a functor/lamba ==> connect(src, &SrcClass::signalName, { qDebug() << "signal received"; })

        take a look at https://doc.qt.io/qt-5/signalsandslots.html for more details.

        D Offline
        D Offline
        Dan203
        wrote on last edited by
        #3

        @KroMignon said in Connect a signal to any function?:

        @Dan203 said in Connect a signal to any function?:

        Is this legal?

        Yes

        Is there any reason I shouldn't do this?

        No

        Now more verbose reply, there are many options to connect a signal. You can connect a signal to:

        • a slot ==> connect(src, SIGNAL(...), dest, SLOT())
        • another signal (for example relaying it) ==> connect(src, SIGNAL(...), dest, SIGNAL())
        • to a member function of a class ==> connect(src, &SrcClass::signalName, dest, &DestClass::functionName)
        • to a functor/lamba ==> connect(src, &SrcClass::signalName, { qDebug() << "signal received"; })

        take a look at https://doc.qt.io/qt-5/signalsandslots.html for more details.

        Thank you. Exactly what I wanted to hear. It's working perfectly in my test and saves me from having to overload every control to add specific slots.

        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