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. What is better? connect in constructor vs. "Go to slot..." in Qt Creator
Forum Update on Monday, May 27th 2025

What is better? connect in constructor vs. "Go to slot..." in Qt Creator

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 2.6k 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.
  • H Offline
    H Offline
    HappyCoder
    wrote on last edited by
    #1

    Hello,
    just a quick question.
    E.g. i have a form created in Qt Creator that contains some QPushButtons, QCheckboxes etc.
    Personally i prefer to use connect inside the constructor to connect signals to slots.
    (especially to connect multiple objects to one slot in a loop and use sender() to get the source of signal).

    I know that i also can be done in Qt Creator by right click on e.g. a QPushButton and use "Go to slot...".
    (this method is prefered by a colleague)

    Everyone has its own style of writing code, but are there any advantages or disadvantages
    for "using connect in constructor" vs. "Use Go to slot... from Qt Creator".

    Thx

    1 Reply Last reply
    1
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome,

      Of course it doesn't matter for the compiler. It doesn't care if the code is generated or written by hand.

      The only differences are for style and maintenance:

      • "Go to slot"
        + ease of use (especially if you come from other languages with visual ui designers)
        + less code in c++ i.e. less "connect text walls".
        - enforces certain slot naming convention that might not match your own
        - susceptible to rename bugs i.e. you rename an object and the code still compiles but silently stops connecting
        - harder to find i.e. you can't just search for "connect", you need to know the name

      • manual connects
        + avoids the problems of "go to slot"
        - more boilerplate code to write

      1 Reply Last reply
      1

      • Login

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