[Interest] Are slots even needed these days?

Giuseppe D'Angelo giuseppe.dangelo at kdab.com
Thu Mar 17 11:40:30 CET 2016


Il 17/03/2016 06:23, Constantin Makshin ha scritto:
> Another thing I personally don't like in the new connection syntax is
> that it forces signals to be public, making it possible to do all type
> of wonders by faking/simulating events on behalf of other objects.
>
> For example:
> QLineEdit* edit = new QLineEdit("foo");
> // ...
> edit->textChanged("bar");

A good counterpart of this is that now a private "slot" is truly 
private, i.e. it's impossible to invoke it externally:

class Foo : public QObject {
     Q_OBJECT

     Foo() {
          connect(something, &Signal, this, &Foo::doFoo);
     }
private slots:
     void doFoo(); // still reachable and invokable via QMetaObject

private:
     void doFoo(); // unreachable from outside
};

Making the signals public is a tradeoff for ease of implementation and 
usage (you would not otherwise be allowed to simply take the address of 
a MF). A check about this could be added to clazy.

Cheers,
-- 
Giuseppe D'Angelo | giuseppe.dangelo at kdab.com | Senior Software Engineer
KDAB (UK) Ltd., a KDAB Group company | Tel: UK +44-1625-809908
KDAB - The Qt Experts

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4068 bytes
Desc: Firma crittografica S/MIME
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160317/ea7542cc/attachment.bin>


More information about the Interest mailing list