[Interest] Requesting QObject::bind() method

alexander golks alex at golks.de
Fri Mar 24 11:19:46 CET 2017


Am Fri, 24 Mar 2017 10:52:47 +0100
schrieb Jean-Michaƫl Celerier <jeanmichael.celerier at gmail.com>:

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

for qt applications i normally have saveState and restoreState methods, 
which will save/restore the current widget and all of relevant child states, like your QLineEdit.
so when restoring the current widgets state, e.g. during construction of the widget itself,
the update is triggered, and you'll see the text in the lable right away.

or, i think, when you do:

  // ...
  w.show();
  text.setText("Some text")

instead of
  QLineEdit text{"Some text"};
  //...
  w.show();

should give you the same result.

in the end,
i think qml hides this implementation details, so you don't have to think about the mechanisms behind this.

alex

-- 
/*
 *Q:  What do you get when you cross a mobster with an international standard?
 *A:  You get someone who makes you an offer that you can't understand!
 */
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 181 bytes
Desc: Digitale Signatur von OpenPGP
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20170324/75531fa8/attachment.sig>


More information about the Interest mailing list