Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-43087

Use MOC to enable clean and simple connection statements

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Out of scope
    • Not Evaluated
    • None
    • None
    • Build tools: moc
    • None

    Description

      The new (and old) connection syntax is too verbose:

      connect(sender, &Sender::valueChanged, receiver, &Receiver::updateValue );

      Even more so when overloads have to be explicitly specified:

      connect(spinbox, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), slider, &QSlider::setValue);

      A possible solution, use a macro + MOC to generate the connection statement from a simpler expression:

      Q_CONNECT(spinbox->valueChanged(int), slider->setValue)

      Example features:

      • detect if a pointer is used "objPtr->someSig" or an instance "obj.someSig" and use the & operator in case of the latter, less prone to errors
      • detect if overload is specified with signal or slot parameter(s) and use static_cast to specify it
      • make it work with non QObject derived classes methods, free functions and lambdas too, and from outside the scope of a QObject derived classes

      Attachments

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

        Activity

          People

            ogoffart Olivier Goffart (Woboq GmbH)
            utcenter Dian Obreshkov
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes