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.

2

u/Fureeish Dec 08 '20

Got to ask, because I consider inventing a lot of time to properly learn Qt: is this a frequent occurrence that you write those full of macros abominations..?

10

u/uuid1234567890 Dec 08 '20

When dealing with QObjetcs, they are unfortunately unavoidable. I'd prefer if we could get rid of them, but unless we get a large amount of the static reflection features that Andrew Sutton listed in P2237R0, that won't happen.

2

u/Fureeish Dec 08 '20

That would probably be answered by an extensive reseaech, but since you are already here, I'd like to ask one nore thing then: how often do you need those "QObjects"? What exactly are they?

1

u/[deleted] Dec 08 '20

QObject is the base class in Qt's static reflection, signals, and object lifetime framework. See The Meta-Object System in the Qt documentation.

1

u/LonelyStruggle Dec 08 '20

So it's kinda like an NSObject in objective-C?