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. Why is it that on_button_clicked() doesn't need a signal?

Why is it that on_button_clicked() doesn't need a signal?

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 919 Views 2 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.
  • Q Offline
    Q Offline
    Q74r3wq-
    wrote on last edited by
    #1

    Hi experts,

    I have a on_<button objectName>_clicked() slot function and somehow it is triggered every time a button is clicked, without any signals defined.

    Now that the button is definitely the most used widget so maybe this is automated under the hood, I still would like know the mechanism, and more importantly which widgets have the same behavior. For example, QTGraphicsView doesn't work this way.

    I already consulted the signal-slot page as well as the QTPushButton page but didn't find what I need.

    Thanks!

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      This is done by QMetaObject::connectSlotsByName which is called as part of the you designer ui object setup method.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      3
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by mrjj
        #3

        Hi
        When you us UI files, the code generated in setupUI calls
        QMetaObject::connectSlotsByName(MainWindow);

        which will try to match widgets and slots

        https://doc.qt.io/qt-5/qmetaobject.html#connectSlotsByName

        hehe one sec too late :)

        In any case. Its far better to use connects in the code as this method suffer from easy to break.

        if you ever rename your widget or the slot - it stops working. silently.
        So for a production-quality app, its best to avoid this feature however handy it is.

        1 Reply Last reply
        3

        • Login

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