0

I am wondering if it's possible to get all context property names of specific QQmlContext.

So I can do something like:

QQmlContext *ctx = ...;

for (auto contextPropertyName: ctx->getPropertyNames()) {
   qDebug() << contextPropertyName << ctx->contextProperty(contextPropertyName);
}

I achieved similar functionality for QObject's with obj->metaObject()->propertyCount() and then obj->metaObject()->property(i).

elderapo
  • 370
  • 2
  • 12
  • Ok, so what is your question? The code you provided doesn't work? – folibis Apr 28 '19 at 06:35
  • There is no `getPropertyNames` method. :) – elderapo Apr 28 '19 at 13:20
  • QQmlContext is derived from `QObject` so you can use qt meta system to loop through the properties ie. `QMetaObject::propertyCount` and `QMetaObject::property(int index)`. – folibis Apr 28 '19 at 14:32
  • I don't believe that is the case. `ctx->property(...)` and `ctx->contextProperty(...)` return different things. Also for me`ctx->metaObject()->propertyCount()` always returns `0` because there is only 1 property `objectName`. – elderapo Apr 28 '19 at 15:29
  • @elderapo Could you describe, what are you going to achieve by possible accessing to `getPropertyNames`? Isn't it [XY-problem](https://en.wikipedia.org/wiki/XY_problem)? – NG_ May 15 '19 at 19:58

1 Answers1

2

You can find your properties using ctx->dynamicPropertyNames();

AAA
  • 3,520
  • 1
  • 15
  • 31