Skip to content

QEP 77: Require use of new style Qt connections for newly added signals/slots #77

@nyalldawson

Description

@nyalldawson

QGIS Enhancement 77: Require use of new style Qt connections for newly added signals/slots

Date 2016/10/28

Author Nyall Dawson (@nyalldawson)

Contact nyall dot dawson at gmail dot com

Version QGIS 3.0

Summary

Many bugs in QGIS stem for incorrectly connected/disconnect signals. The signature of a signal or slot changes in a subtle way, and without any warning (assuming no unit test coverage of the affected code!) boom ... something breaks.

Qt5 brings a new method to connect signals and slots. The main benefit of the new method is a compile time error when the connection cannot be created. Having this breakage occur at compile time (and hence caught by the CI testing... and also... you know... people actually compiling their own changes) means that the issue is caught before the offending code is ever committed to the codebase. Win!

A good summary of the new connection method, including some of the advantages (and disadvantages), and possible traps, is available at https://wiki.qt.io/New_Signal_Slot_Syntax

Proposed Solution

We require use of the new style connections for ALL NEWLY INTRODUCED signals/slots ONLY.

The important point here is that this only applies to new signals and slots. Adding new code which connects existing signals to existing slots is not affected by this QEP. The rationale behind this distinction is that it is not possible to disconnect using the old way any connections which have been made using the new method. If careful consideration is not made when creating a connection using existing signals and slots then it is possible that existing code which disconnects these signals/slots will no longer function correctly. Rather then apply a blanket rule of "all new code must use the new method" it is instead proposed a safer approach of:

  • any NEWLY introduced signals/slots must use the new style connects/disconnects
  • you should continue to use old style connections for existing signals/slots UNLESS you carefully do due diligence to ensure that no old style disconnects are in place anywhere else in the existing code which may be affected by use of a new style connection

Example(s)

See the Qt docs at https://wiki.qt.io/New_Signal_Slot_Syntax

Old

connect(sender, SIGNAL (valueChanged(QString,QString)), receiver, SLOT (updateValue(QString)) );

New

connect(sender, &Sender::valueChanged, receiver, &Receiver::updateValue );

Backwards Compatibility

N/A

Votes

(required)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions