[Development] Question about QtDeclarative Internals

Ulf Hermann ulf.hermann at qt.io
Thu Apr 22 07:54:15 CEST 2021

Hi Alex,

the simplest way I can see here would not be a compilation unit. The 
compilation unit is only needed if you want to run JavaScript. The place 
where the imports of a script are saved is 
QV4::CompiledData::CompilationUnitBase::imports of the _importing_ unit. 
That's an array QV4::StaticValue*. Imports are always resolved 
statically when loading the script that does the import.

You need a way to tell the engine "Hey, here is my implementation of 
foobar, use that when importing foobar in JavaScript". Then you can just 
provide a QV4::Value (that has been protected against garbage collection 
in some way) as that will fit the bill for the imports array.

You might store those values as a hash of QUrl to QV4::PersistentValue 
in QV4::ExecutionEngine. Then you can query them in addition to the 
compilation units whenever something is imported. In a second step, the 
original modules hash may be changed to store some abstraction over both 

This of course does involve some changes in the QML engine itself. 
However, better integration of C++ into JavaScript (as opposed to QML) 
has been on my list for a long time. This would be a welcome addition. 
Don't hesitate to ask me if you have further questions. You can also 
find me on freenode IRC in the #qt-v4vm channel.

best regards,

More information about the Development mailing list