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. Which class should be used to connect a signal ?

Which class should be used to connect a signal ?

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

    Hi,

    As far as I know, the following lines should be equivalent :

    QObject::connect(ui->button, &QPushButton::clicked, this, []() {});
    QObject::connect(ui->button, &QAbstractButton::clicked, this, []() {});
    

    Most examples and Qt sources tends to favor the first using the actual widget class. Does it make any difference ? And if there are, what are the benefits/drawbacks of both ?

    The second makes code less susceptible to UI changes (replacing QPushButton with QRadioButton for example), and in any case, if the class/method doesn't match, it would result in a build error. I don't know if this is even possible, but the derived class could hide the signal from the base class causing issues, no ?

    Thank you in advance !

    1 Reply Last reply
    0
    • Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by Christian Ehrlicher
      #2

      @Tudal said in Which class should be used to connect a signal ?:

      Does it make any difference ?

      No, use what you like. I mostly use the class of the pointer before since I don't care in which base class the signal or slot is defined.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      2

      • Login

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