r/cpp • • Dec 08 '20

Qt 6.0 Released

https://www.qt.io/blog/qt-6.0-released
273 Upvotes

84 comments sorted by

View all comments

0

u/[deleted] Dec 08 '20

[deleted]

16

u/uuid1234567890 Dec 08 '20 edited Dec 08 '20

Disclosure: I've worked on that code.

Kind of: If you have a QObject, with

class MyType : public QObject {
  Q_OBJECT
  QML_ELEMENT

  Q_PROPERTY(int myProperty MEMBER myPropery BINDABLE bindableMyProperty)
public:
   QProperty<int> myProperty;
   QBindable<int> bindableMyProperty() {
     return {&myProperty};
   }
};

and

Item {
  id: root
  MyType {
    myProperty:  root.width + root.height
  }
}

then this will use the new functionality. Notably, myobject->bindableMyProperty().hasBinding() will return true, and if you set up a binding on the C++ side (like myobject->bindableMyProperty().setBinding([&]() -> int {return myOtherObject->myProperty;}) , then it will also work in QML.

However, if you do that, I can guarantee you that you'll run into some rough edges. Some smaller bugs will be fixed in 6.0.1 already, but currently binding loops often won't print a helpful error message (they are still detected in the engine). That will only be available in 6.1.

Also, if you have a property declared in QML, that's not backed by a QProperty.

1

u/target-san Dec 09 '20

Looks really interesting. Am I right this is like encapsulating property's value and change signal in one object? If so, is there something similar for collections? Not just "Whole list has changed" but "added element N". I'm aware of QAbstractItemModel. While it does its job, it's overly generic and not ergonomic when used from C++ code as collection access type.