Better_Software_Header_MobileBetter_Software_Header_Web

Find what you need - explore our website and developer resources

Nailing 13 signal and slot mistakes with clazy 1.3

Create better Qt code by automatically uncovering easy-to-miss errors

 connect(obj, &MyObj::mySlot, &MyObj::mySlot2);
warning: MyObj::mySlot is not a signal [-Wclazy-connect-non-signal]

void myFunction()
{
    int localVar = ...;

    // program will crash when signal is emitted!
    connect(m_object, &MyObj::mySignal, [&localVar] { ... });
}

connect(m_widget, &MyWidget::textChanged, [this] (const QString &text) {
    m_receiver->update(text, false);
});

connect(m_widget, &MyWidget::textChanged, m_receiver,
        [this] (const QString &text) { (....) });

    // warning: Signature is not normalized. Use void mySlot(int) instead of void mySlot(const int) [-Wclazy-connect-not-normalized]
    o.connect(&o, SIGNAL(mySignal(int, int)),
              &o, SLOT(void mySlot(const int)));

19 Comments

24 - Jan - 2018

Gunnar Roth

24 - Jan - 2018

Sérgio Martins

24 - Jan - 2018

Gunnar Roth

24 - Jan - 2018

Sérgio Martins

24 - Jan - 2018

Jean-Michaël Celerier

struct MyObject : QObject, IFoo, IBar { 
  Q_OBJECT
  public: ...
  signals:
    void fooChanged(int) override;
    void barChanged(QString) override;
};
struct MyObject : QObject { 
  Q_OBJECT
  public: 
    Foo foo;
    Bar bar;
};

24 - Jan - 2018

Sérgio Martins

28 - Jan - 2018

Jean-Michaël Celerier

24 - Jan - 2018

Michael Vlach

19 - Apr - 2018

Eike Ziller

24 - Jan - 2018

Sérgio Martins

25 - Jan - 2018

Markus

25 - Jan - 2018

Sérgio Martins

25 - Jan - 2018

Tim Angus

25 - Jan - 2018

Sérgio Martins

26 - Jan - 2018

Tim Angus

26 - Jan - 2018

Tim Angus

26 - Jan - 2018

Sérgio Martins

26 - Jan - 2018

Tim Angus

24 - Apr - 2018

f.zweig

SérgioMartins

Sérgio Martins

Senior Software Engineer

Learn Modern C++

Learn more