[Interest] Requesting QObject::bind() method

Jean-Michaƫl Celerier jeanmichael.celerier at gmail.com
Fri Mar 24 10:52:47 CET 2017


On Fri, Mar 24, 2017 at 12:50 AM, Thiago Macieira <thiago.macieira at intel.com
> wrote:

>
> The new value is already carried by the signal. We don't need the getter:
> my
> code examples already compile.
>

I really think that we do.

For instance in the following code:

#include <QApplication>
#include <QLabel>
#include <QVBoxLayout>
#include <QLineEdit>
int main(int argc, char *argv[])
{
  QApplication a(argc, argv);

  QWidget w;
  QVBoxLayout lay;
  QLabel label;
  QLineEdit text{"Some text"};
  lay.addWidget(&label);
  lay.addWidget(&text);

  QObject::connect(&text, &QLineEdit::textChanged,
          &label, &QLabel::setText);

  w.setLayout(&lay);
  w.show();

  return a.exec();
}

when running the application, the label has no text, and takes the
lineedit's text only when the lineedit changes.

Instead, with QtQuick:

import QtQuick 2.0
import QtQuick.Controls 2.0
Rectangle {
  Column {
  Text {
    text: edit.text
  }

  TextField {
    id: edit
    text: "Some text"
  }
  }
}

when the application starts, the label is already set at "Some text"
through the binding

> Why? We have a perfectly working method that uses PMFs and delivers to
callables, without additional magic.

Because I'm getting wrist pain every time I have to type &QSomething:: and
the same safety can be achieved.
I assumed C++17 would be okay because when compiling qt I see a lot of
std=C++1z.
Of course, reactive bindings like the ones provided by Olivier Goffart are
even better from a programming quality standpoint, but requires bigger
changes in user code.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20170324/e46b3027/attachment.html>


More information about the Interest mailing list