Hi Ulf
Thanks for the feedback. The reason it was done like this is it was a
simple replacement for console.log that didn't require any imports. So
it would just work throughout the 50 odd modules and 1000 qml files. It
was essentially added as an object in the engine's context (which is the
global object), like this (where 'logger' is a QObject derived class
with invokables for the log methods):
//----------------------------------------------------------------------//
void AddLogger(const QString& name, QObject* logger, QQmlContext*
context)
{
logger->setParent(context);
QQmlEngine::setContextForObject(logger, context);
context->setContextProperty(name, logger);
}
It sounds like a singleton in a module is the way it should be done though.
Thank you
Matthew
On 2023/08/31 17:42, Ulf Hermann via Interest wrote:
I was not going to add them to jsroot.qmltypes. I was wondering if
there was a mechanism to extend what is defined in jsroot.qmltypes.
That is pretty much the same thing. jsroot.qmltypes represents the
JavaScript global object. Since all of this is pure JavaScript, we can
generally not say much about the types involved. However, since the
JavaScript global object is supposed to be immutable in a QQmlEngine
(I wonder how you managed to add something to it, btw), we actually
_know_ what is in there because we know the precise implementation in
the engine's internals. Once you start adding something there, we
don't know anything about the types anymore. So, don't.
best regards,
Ulf Hermann
_______________________________________________
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