Yeah, that would be a nice addition and help people debug their
application.

We are using Qml as scripting engine to assemble our application block
(behavior, 2D GUI, 3D GUI we are doing rendering to a texture with our own
backend engine, we started before Qt3D). We have a lot of Qml Scripts and
complexe one, we are doing medical CAD application. It's going surprising
well, we even have some OpenCL kernel running from Qml string into scripts,
late evaluation of product, geometry manipulation, opengl scene and
interaction, etc.

if some are intersted:
http://bodycad.com/en/a-new-way-to-prep/software

We went a bit too far at some point, but it got us by surprise how we could
just use the Qml, not only for display but as a whole scripting engine.
Most heavy algo are in C++ but assemble the application was possible, the
why we have many function like this one to help us debug. Sadly, some
require our framework to work with, so I cannot share them :-(

Enjoy ;-)


On Thu, Mar 10, 2016 at 4:57 PM, Jason H <jh...@gmx.com> wrote:

> Awesome! Thanks.
>
> But shouldn't this be in QML by default? Seems like it'd be a simple thing
> to add and use?
>
>
>
> *Sent:* Thursday, March 10, 2016 at 1:10 PM
> *From:* "Jérôme Godbout" <jer...@bodycad.com>
> *To:* "Jason H" <jh...@gmx.com>
> *Cc:* "Dmitry Volosnykh" <dmitry.volosn...@gmail.com>, "
> interest@qt-project.org" <interest@qt-project.org>
>
> *Subject:* Re: [Interest] QML id property to string?
> Another useful one:
>
> Q_INVOKABLE QString MySingleton::ownership( QObject * object ) const
> {
> auto ownership = QQmlEngine::contextForObject(object)->engine()
> ->objectOwnership(object);
> switch(ownership)
> {
> case QQmlEngine::CppOwnership: return QString("CppOwnership");
> case QQmlEngine::JavaScriptOwnership: return
> QString("JavaScriptOwnership");
> default: break;
> }
>        return QString("error");
> }
>
> On Thu, Mar 10, 2016 at 1:07 PM, Jérôme Godbout <jer...@bodycad.com>
> wrote:
>>
>> You can create a C++ method for this, expose it into a C++ singleton to
>> easily access it:
>>
>> Q_INVOKABLE QString MySingleton::idName(QObject * object) const
>> {
>> const auto context = qmlContext(object);
>> return context ? context->nameForObject(object): QString("context not
>> found");
>> }
>>
>> http://doc.qt.io/qt-5/qqmlcontext.html#nameForObject
>>
>> For Qml it return the context id.
>>
>> Other useful methods would be address and file where the object come from:
>> Q_INVOKABLE QString MySingleton::objHexAddress(QObject * object) const
>> {
>> return QString().sprintf("%08p", object);
>> }
>>
>> Q_INVOKABLE QUrl MySingleton::whereAmIDeclared(QObject * object) const
>> {
>> if (object)
>> if (auto context = QQmlEngine::contextForObject(object))
>> return context->baseUrl();
>> return QUrl();
>> }
>>
>> This help a lot to debug into the console.
>> Regards,
>> Jerome
>>
>> On Thu, Mar 10, 2016 at 12:45 PM, Jason H <jh...@gmx.com> wrote:
>>>
>>> Yes, Ideally what I want:
>>> 1. Be able to get object id as string
>>> 2. Search the object heirarchy for that string and get that object
>>>
>>> *Sent:* Thursday, March 10, 2016 at 12:14 PM
>>> *From:* "Dmitry Volosnykh" <dmitry.volosn...@gmail.com>
>>> *To:* "Jason H" <jh...@gmx.com>, "interest@qt-project.org" <
>>> interest@qt-project.org>
>>> *Subject:* Re: [Interest] QML id property to string?
>>> I feel the same need frequently, too. Without such feature I have to set
>>> objectName by copy-pasting and qouting id. This is quite annoying.
>>>
>>> On Thu, Mar 10, 2016 at 8:08 PM Jason H <jh...@gmx.com> wrote:
>>>
>>>> A few times now, I've wanted to display the id as a string. Usually
>>>> when something goes wrong on the console, but sometimes in a hash/map.
>>>> I've got a function that takes an object (QML item) and does some
>>>> processing on it. Is there a way to get it? I know I can just set a
>>>> property, but then that has to be maintained separately.
>>>> _______________________________________________
>>>> Interest mailing list
>>>> Interest@qt-project.org
>>>> http://lists.qt-project.org/mailman/listinfo/interest
>>>
>>>
>>> _______________________________________________
>>> Interest mailing list
>>> Interest@qt-project.org
>>> http://lists.qt-project.org/mailman/listinfo/interest
>>>
>>
>>
_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to