[Qt-creator] Proposals for Updating the Qt Creator Coding Style

Daniel Teske daniel.teske at digia.com
Thu Oct 2 11:30:30 CEST 2014


On Thursday 02 Oct 2014 10:01:30 Christian Kandeler wrote:
> On 10/01/2014 04:21 PM, Daniel Teske wrote:
> > ** Qt5 connects vs Qt4 connects
> > 
> > - Prefer to use qt5 style connects with member function pointers to the
> > qt4
> > style of using SIGNAL and SLOT macros.
> > 
> > - Avoid overloading signals or slots
> > - Avoid calling connect via "object->connect()"
> 
> Can you elaborate on the latter point? I forgot the reason.
The reason is that it's different between the qt4 connect and the qt5 connect.

With qt4 connects,
a->connect(b, SIGNAL(sig(), SLOT(slot()))
is equivalent to
connect(b, SIGNAL(sig()), a, SLOT(slot()));

because there is a member method connect for that. Thus the connection is 
removed if "a" is deleted

whereas:
a->connect(b, &B::sig, &A::slot),

calls the *static* connect method, that takes no context object, so the 
connection is not removed if "a" is deleted.

For that reason I'd like to discourage using the member functions at all.

daniel



More information about the Qt-creator mailing list