[Interest] How to set a non-global context property for a single QQmlComponent?
Hello! Surely there must be a way to set a context property on a single component without having to set it globally on the entire QQmlEngine? Indeed, the QQmlContext documentation is silent on this point. Help?? ___ Interest mailing list Interest@qt-project.org https://lists.qt-project.org/listinfo/interest
Re: [Interest] How to set a non-global context property for a single QQmlComponent?
On 2019-07-17 10:15, Patrick Stinson wrote: Hello! Surely there must be a way to set a context property on a single component without having to set it globally on the entire QQmlEngine? Indeed, the QQmlContext documentation is silent on this point. Help?? Hi, You can create a child QQmlContext via this constructor [1], and then pass it to QQmlComponent::create() [1] - https://doc.qt.io/qt-5/qqmlcontext.html#QQmlContext-1 Regards, -- Sérgio Martins | sergio.mart...@kdab.com | Senior Software Engineer Klarälvdalens Datakonsult AB, a KDAB Group company Tel: Sweden (HQ) +46-563-540090, USA +1-866-777-KDAB(5322) KDAB - The Qt, C++ and OpenGL Experts ___ Interest mailing list Interest@qt-project.org https://lists.qt-project.org/listinfo/interest
Re: [Interest] How to set a non-global context property for a single QQmlComponent?
Shoot, you know at first pass it looks like that will work. Wow. I wonder if this is possible to do with QQuickWidget? Or if not how to show a component into a QWidget without QQuickWidget? > On Jul 17, 2019, at 1:35 AM, Sérgio Martins wrote: > > On 2019-07-17 10:15, Patrick Stinson wrote: >> Hello! >> Surely there must be a way to set a context property on a single >> component without having to set it globally on the entire QQmlEngine? >> Indeed, the QQmlContext documentation is silent on this point. >> Help?? > > Hi, > > > You can create a child QQmlContext via this constructor [1], and then pass it > to QQmlComponent::create() > > > > [1] - https://doc.qt.io/qt-5/qqmlcontext.html#QQmlContext-1 > > Regards, > -- > Sérgio Martins | sergio.mart...@kdab.com | Senior Software Engineer > Klarälvdalens Datakonsult AB, a KDAB Group company > Tel: Sweden (HQ) +46-563-540090, USA +1-866-777-KDAB(5322) > KDAB - The Qt, C++ and OpenGL Experts ___ Interest mailing list Interest@qt-project.org https://lists.qt-project.org/listinfo/interest
Re: [Interest] How to set a non-global context property for a single QQmlComponent?
On 2019-07-17 10:58, Patrick Stinson wrote: Shoot, you know at first pass it looks like that will work. Wow. I wonder if this is possible to do with QQuickWidget? Or if not how to show a component into a QWidget without QQuickWidget? According to [1] it's not possible, but could be an easy patch to add to QQuickWidget's API. [1] https://code.woboq.org/qt5/qtdeclarative/src/quickwidgets/qquickwidget.cpp.html#1049 On Jul 17, 2019, at 1:35 AM, Sérgio Martins wrote: On 2019-07-17 10:15, Patrick Stinson wrote: Hello! Surely there must be a way to set a context property on a single component without having to set it globally on the entire QQmlEngine? Indeed, the QQmlContext documentation is silent on this point. Help?? Hi, You can create a child QQmlContext via this constructor [1], and then pass it to QQmlComponent::create() [1] - https://doc.qt.io/qt-5/qqmlcontext.html#QQmlContext-1 -- Sérgio Martins | sergio.mart...@kdab.com | Senior Software Engineer Klarälvdalens Datakonsult AB, a KDAB Group company Tel: Sweden (HQ) +46-563-540090, USA +1-866-777-KDAB(5322) KDAB - The Qt, C++ and OpenGL Experts ___ Interest mailing list Interest@qt-project.org https://lists.qt-project.org/listinfo/interest
Re: [Interest] How to set a non-global context property for a single QQmlComponent?
Is there any way other than QQuickWidget to show a Qml Component in a QWidget? > On Jul 17, 2019, at 2:14 AM, Sérgio Martins wrote: > > On 2019-07-17 10:58, Patrick Stinson wrote: >> Shoot, you know at first pass it looks like that will work. Wow. >> I wonder if this is possible to do with QQuickWidget? Or if not how to >> show a component into a QWidget without QQuickWidget? > > > According to [1] it's not possible, but could be an easy patch to add to > QQuickWidget's API. > > > [1] > https://code.woboq.org/qt5/qtdeclarative/src/quickwidgets/qquickwidget.cpp.html#1049 > > > >>> On Jul 17, 2019, at 1:35 AM, Sérgio Martins wrote: >>> On 2019-07-17 10:15, Patrick Stinson wrote: Hello! Surely there must be a way to set a context property on a single component without having to set it globally on the entire QQmlEngine? Indeed, the QQmlContext documentation is silent on this point. Help?? >>> Hi, >>> You can create a child QQmlContext via this constructor [1], and then pass >>> it to QQmlComponent::create() >>> [1] - https://doc.qt.io/qt-5/qqmlcontext.html#QQmlContext-1 > > > > > -- > Sérgio Martins | sergio.mart...@kdab.com | Senior Software Engineer > Klarälvdalens Datakonsult AB, a KDAB Group company > Tel: Sweden (HQ) +46-563-540090, USA +1-866-777-KDAB(5322) > KDAB - The Qt, C++ and OpenGL Experts ___ Interest mailing list Interest@qt-project.org https://lists.qt-project.org/listinfo/interest
Re: [Interest] How to set a non-global context property for a single QQmlComponent?
On 2019-07-17 10:58, Patrick Stinson wrote: Shoot, you know at first pass it looks like that will work. Wow. I wonder if this is possible to do with QQuickWidget? Or if not how to show a component into a QWidget without QQuickWidget? A colleague of mine offered a workaround: QQmlContext *subContext = QQmlEngine::contextForObject(myQuickWidget.rootObject()) That should be a subContext already, different from the engine->rootContext() Regards, Sergio On Jul 17, 2019, at 1:35 AM, Sérgio Martins wrote: On 2019-07-17 10:15, Patrick Stinson wrote: Hello! Surely there must be a way to set a context property on a single component without having to set it globally on the entire QQmlEngine? Indeed, the QQmlContext documentation is silent on this point. Help?? Hi, You can create a child QQmlContext via this constructor [1], and then pass it to QQmlComponent::create() [1] - https://doc.qt.io/qt-5/qqmlcontext.html#QQmlContext-1 Regards, -- Sérgio Martins | sergio.mart...@kdab.com | Senior Software Engineer Klarälvdalens Datakonsult AB, a KDAB Group company Tel: Sweden (HQ) +46-563-540090, USA +1-866-777-KDAB(5322) KDAB - The Qt, C++ and OpenGL Experts -- Sérgio Martins | sergio.mart...@kdab.com | Senior Software Engineer Klarälvdalens Datakonsult AB, a KDAB Group company Tel: Sweden (HQ) +46-563-540090, USA +1-866-777-KDAB(5322) KDAB - The Qt, C++ and OpenGL Experts ___ Interest mailing list Interest@qt-project.org https://lists.qt-project.org/listinfo/interest
Re: [Interest] How to set a non-global context property for a single QQmlComponent?
Right, I did try that one but if I remember right I got an error setting the context property, or that it was the same as the engine root context. > On Jul 17, 2019, at 3:37 AM, Sérgio Martins wrote: > >> On 2019-07-17 10:58, Patrick Stinson wrote: >> Shoot, you know at first pass it looks like that will work. Wow. >> I wonder if this is possible to do with QQuickWidget? Or if not how to >> show a component into a QWidget without QQuickWidget? > > A colleague of mine offered a workaround: > QQmlContext *subContext = > QQmlEngine::contextForObject(myQuickWidget.rootObject()) > > That should be a subContext already, different from the engine->rootContext() > > Regards, > Sergio > >>> On Jul 17, 2019, at 1:35 AM, Sérgio Martins wrote: On 2019-07-17 10:15, Patrick Stinson wrote: Hello! Surely there must be a way to set a context property on a single component without having to set it globally on the entire QQmlEngine? Indeed, the QQmlContext documentation is silent on this point. Help?? >>> Hi, >>> You can create a child QQmlContext via this constructor [1], and then pass >>> it to QQmlComponent::create() >>> [1] - https://doc.qt.io/qt-5/qqmlcontext.html#QQmlContext-1 >>> Regards, >>> -- >>> Sérgio Martins | sergio.mart...@kdab.com | Senior Software Engineer >>> Klarälvdalens Datakonsult AB, a KDAB Group company >>> Tel: Sweden (HQ) +46-563-540090, USA +1-866-777-KDAB(5322) >>> KDAB - The Qt, C++ and OpenGL Experts > > -- > Sérgio Martins | sergio.mart...@kdab.com | Senior Software Engineer > Klarälvdalens Datakonsult AB, a KDAB Group company > Tel: Sweden (HQ) +46-563-540090, USA +1-866-777-KDAB(5322) > KDAB - The Qt, C++ and OpenGL Experts ___ Interest mailing list Interest@qt-project.org https://lists.qt-project.org/listinfo/interest
Re: [Interest] How to set a non-global context property for a single QQmlComponent?
On Wednesday, 17 July 2019, Patrick Stinson wrote: > Right, I did try that one but if I remember right I got an error setting the > context property, or that it was the same as the engine root context. I would expect that QQmlEngine::contextForObject() as well as qmlContext() returns a private read-only context, even if there is a writeable context further up in the hierarchy. You could try to call parentContext() to get the writeable context of the component (usually a child of the engine's root context. See https://bugreports.qt.io/plugins/servlet/mobile#issue/QTBUG-69075 for a bit more information about internal vs global contexts. Richard > > On Jul 17, 2019, at 3:37 AM, Sérgio Martins wrote: > > > >> On 2019-07-17 10:58, Patrick Stinson wrote: > >> Shoot, you know at first pass it looks like that will work. Wow. > >> I wonder if this is possible to do with QQuickWidget? Or if not how to > >> show a component into a QWidget without QQuickWidget? > > > > A colleague of mine offered a workaround: > > QQmlContext *subContext = > > QQmlEngine::contextForObject(myQuickWidget.rootObject()) > > > > That should be a subContext already, different from the > > engine->rootContext() > > > > Regards, > > Sergio > > > >>> On Jul 17, 2019, at 1:35 AM, Sérgio Martins > >>> wrote: > On 2019-07-17 10:15, Patrick Stinson wrote: > Hello! > Surely there must be a way to set a context property on a single > component without having to set it globally on the entire QQmlEngine? > Indeed, the QQmlContext documentation is silent on this point. > Help?? > >>> Hi, > >>> You can create a child QQmlContext via this constructor [1], and then > >>> pass it to QQmlComponent::create() > >>> [1] - https://doc.qt.io/qt-5/qqmlcontext.html#QQmlContext-1 > >>> Regards, > >>> -- > >>> Sérgio Martins | sergio.mart...@kdab.com | Senior Software Engineer > >>> Klarälvdalens Datakonsult AB, a KDAB Group company > >>> Tel: Sweden (HQ) +46-563-540090, USA +1-866-777-KDAB(5322) > >>> KDAB - The Qt, C++ and OpenGL Experts > > > > -- > > Sérgio Martins | sergio.mart...@kdab.com | Senior Software Engineer > > Klarälvdalens Datakonsult AB, a KDAB Group company > > Tel: Sweden (HQ) +46-563-540090, USA +1-866-777-KDAB(5322) > > KDAB - The Qt, C++ and OpenGL Experts > ___ > Interest mailing list > Interest@qt-project.org > https://lists.qt-project.org/listinfo/interest > ___ Interest mailing list Interest@qt-project.org https://lists.qt-project.org/listinfo/interest