[Development] Question about QtDeclarative Internals

Jason H jhihn at gmx.com
Wed Apr 21 19:01:35 CEST 2021

> Hello,
> In QtDeclarative, can a QV4::ReturnedValue or a QV4::Value be converted into an ExecutableCompilationUnit?
> I'm trying to work on a patch for QJSEngine to allow importing modules from C++ (similar to Node.js: import fs from "fs")
> The planned method is something along the lines of:
> void QJSEngine::registerModule(const QString &moduleName, const QJSValue &value)
> I can see that behind the scenes, loadModule compiles a URL to an ExecutableCompilationUnit, then saves it to a list of modules for future lookup.
> I thought the easiest way to do what I need is to convert a QJSValue to an internal QV4::Value, and from there into an ExecutableCompilationUnit.
> Is there any way of doing that?

This may not be what you asked for, but having done NodeJS, I would probably just recommend importing a Qt QObject as a Singleton to expose the functions under the fa import.
See qmlRegisterSingletonType().

import org.mine.fs 1.0

var file = fs.openFileSync(...);

More information about the Development mailing list