Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Connecting custom slots whith signals using Qt Designer
Qt 6.11 is out! See what's new in the release blog

Connecting custom slots whith signals using Qt Designer

Scheduled Pinned Locked Moved Qt Creator and other tools
7 Posts 3 Posters 7.2k 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.
  • F Offline
    F Offline
    freecamellia
    wrote on last edited by
    #1

    Hi,
    I defined some slots in form.cpp, can I connecting them with signals using Qt Designer (i.e. by selecting them from a list) ?

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

      No, this is not possible, as Qt Designer does not have knowledge of the slots you've added to your class.

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andre
        wrote on last edited by
        #3

        Indeed, no. However, perhaps you can use the autoconnect syntax for naming your slots, so they get connected automatically?

        1 Reply Last reply
        0
        • F Offline
          F Offline
          freecamellia
          wrote on last edited by
          #4

          Thanks, the syntax is as follows :

          @void on_<object name>_<signal name>(<signal parameters>);@

          but if I have to connect it with multiple signals what's the naming?

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

            You cannot do that automatically, you will have to do that manually from code. Note that even for the autoconnect syntax above, there is a snag. The object names from designer by default contain underscores ("pushbutton_2"), but those get in the way of the auto connect magic. It is a good idea to rename widgets on your forms to something more informative anyway, but you will have to do that if you want to use the autoconnect features.

            Personally, I don't really like that feature at all, and prefer to have all connections made explicitly to methods that I can then give a proper name. Sometimes onMyButtonClicked may be an appropriate name for a slot, but most often I want to describe the actual action (moveToAdvancedState) instead of describing what triggered its execution. Also, the mechanism promotes non-Qt like naming for methods. The Qt API uses camel casing for method names, not underscores.

            1 Reply Last reply
            0
            • F Offline
              F Offline
              freecamellia
              wrote on last edited by
              #6

              Thank you very much for these interesting informations.
              I think that connecting visually a custom slot with one or more custom signals without using autoconnect syntax for naming is very innovative feature that it can be added easily by a simple parsing of the .h file.

              1 Reply Last reply
              0
              • G Offline
                G Offline
                goetz
                wrote on last edited by
                #7

                No, it cannot be added easily. Designer does not know of the use of your form.ui file at all - which is a good thing™. You might want to use it in a QUiLoader which doesn't have that surrounding class, etc. It would only work with a very limited use case of the forms and I'm not convinced whether it's worth the effort.

                http://www.catb.org/~esr/faqs/smart-questions.html

                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