SDK Qt Creator autocomplete removes const from SIGNAL and SLOT signatures

asked 2014-08-06 10:10:58 +0200

smoku gravatar image

updated 2014-08-06 11:22:57 +0200

jiit gravatar image

When you use autocomplete to write connect() statements, autocompleted SIGNAL() and SLOT() signatures have 'const' removed. i.e signal of definition void foo(const QString &); gets autocompleted as SIGNAL(foo(QString&)).

This causes difficult to comprehend no such signal and no such slot errors on runtime.

edit retag flag offensive close delete

Comments

Have you got example source code with which this can be reproduced?

I believe your example above should get autocompleted to SIGNAL(foo(QString)). The const or & should not be part of the autocompletion or the code you write. It seems to work as I described for me, but perhaps you have some code segment that is triggering an error in autocompletion?

kaltsi ( 2014-08-19 12:46:34 +0200 )edit

Here's a bugfix for such an error: https://github.com/smokku/pebble/commit/e47e1202518ab72658ab8d659b081b71fdd8609f#diff-90291d1305a30fca5e4a577b83910a7eR28

The issue is that QDBusConnectionInterface emits void serviceUnregistered(const QString &) but autocompleted signature is SIGNAL(serviceRegistered(QString&)), which gets compiled OK (as SIGNAL macro generates plain string) but errors on runtime, with "no such signal" error.

smoku ( 2014-08-19 14:42:08 +0200 )edit

Yeah, I can get that funky autocompletion with the serviceUnregistered signal.

It might have something to do with the way the signal is declared in qt's own header file (qdbusconnectioninterface.h):

void serviceUnregistered(const QString &service);

If I change that to have a space between the "&" and "service", then the autocompletion will insert just serviceRegistered(QString) there without the const and &, which is fine.

So it looks like a bug in Qt Creator. Will have to check if it's still there in Qt Creator 3.x.

kaltsi ( 2014-08-19 14:52:51 +0200 )edit

Unfortunately it does not work any better in Qt Creator 3. By the way, this article and some Qt's own documentation prefers normalised signatures over const references:

http://marcmutz.wordpress.com/effective-qt/prefer-to-use-normalised-signalslot-signatures/

kaltsi ( 2014-08-19 15:58:30 +0200 )edit