Details
-
Suggestion
-
Resolution: Fixed
-
Not Evaluated
-
None
-
None
-
e2756fde8 (master)
Description
I get cognitive dissonance when deciding whether to use:
object->method(arg1, arg2);
vs.
QMetaObject::invokeMethod(object, "method", Q_ARG(int,arg1), Q_ARG(bool,arg2));
The first version is faster to write and auto-completion/etc kicks in to help me write the method name and arguments, but the second version uses Qt::AutoConnection so is safer in the face of 'object' being [later] moved to another thread.
A QtCreator refactor-action/quick-fix could give us the best of both worlds. Detect 'object' is QObject derived, then that 'method' is a slot, then offer to do it (on right click -> refactor or Alt+Enter or wherever). Determining the types of the arguments would probably be the most difficult part.
Additionally:
...could even go further and a similar quick-fix could add a signal to 'this' with a signature that matches 'method' (perhaps name the signal 'methodRequested'), and connect the two and give the emit. But the QMetaObject::invokeMethod version should still exist of course because maybe 'this' isn't a QObject (int main, perhaps?) etc.