Uploaded image for project: 'Qt Creator'
  1. Qt Creator
  2. QTCREATORBUG-15972

Add a refactor/quick-fix to convert vanilla C++ method invocation to QMetaObject::invokeMethod

    XMLWordPrintable

Details

    • 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.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            kandeler Christian Kandeler
            d3fault d3fault
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes