[Interest] Are slots even needed these days?
Yves Bailly
Yves.Bailly at verosoftware.com
Wed Mar 16 15:42:02 CET 2016
A use case for "old-style" slots is when you have dynamic connections, established at runtime
from some config file: you get the names of the signals and the slots as strings.
With the old style, your code can be as simple as
QObject::connect(foo, signal_name_string, bar, slot_name_string);
With the new style, you would have to manually map the strings to the function pointers, hence modifying the connection code each time a new signal or slot is added.
--
Yves Bailly
Software developer
> -----Original Message-----
> From: Interest [mailto:interest-bounces+yves.bailly=verosoftware.com at qt-
> project.org] On Behalf Of Nikos Chantziaras
> Sent: Wednesday, March 16, 2016 3:25 PM
> To: interest at qt-project.org
> Subject: [Interest] Are slots even needed these days?
>
> Since in modern Qt you connect signals to functions/lambdas, is there a
> reason to declare slots anymore?
>
> In other words, is there any difference between:
>
> class Foo: public QObject {
> Q_OBJECT
>
> public slots:
> void bar();
> };
>
> and:
>
> class Foo: public QObject {
> Q_OBJECT
> public:
>
> void bar();
> };
>
> I can connect to Foo::bar either way. If I don't intend to ever use the
> old-style connect syntax, is there a reason to have "public slots:"
> anymore?
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
More information about the Interest
mailing list