Qt World Summit: Submit your Presentation

Slot are not defined but works fine even without connection to signal

  • Hello,

    I have no serious Qt programming experience. I made a form based on QDialog, in which I have QDialogButtonBox. In order for the form to respond to pressing the "OK" button of class QDialogButtonBox, in theory, you need to connect an "accepted" QDialogButtonBox class signal to an "my_slot" QDialog class slot. However, since there was very little experience, I googled every step or read the documentation to complete the task. As a result, I implemented it in way I can not find the information now where I found such a solution, but the solution is good.

    Object name of My QDialogButtonBox is "Login"
    In class QDialog, i added slot -on_Login_accepted().
    That is all. I not made any connection of this slot to any signals and all works fine. I just named my slot : on_(name of my object)_accepted()
    and it works. Connection was made automatically.

    Could anybody explain or better give link to where i can read about it, please.

    P.S. Sorry for my English if somesing wrong. I hope you understand me)

  • @Lisun
    It is because of the actual name you (Qt Creator) chose for the slot, on_Login_accepted(), which is of the form void on_<object name>_<signal name>. See https://doc.qt.io/qt-5/designer-using-a-ui-file.html#widgets-and-dialogs-with-auto-connect. Some people choose to do it this way automatically, some prefer to use a different name for the slot and do the connect()s explicitly/manually.

  • @JonB Thanks a lot for quick response

Log in to reply