Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

462
Views
Qt: Import Qml Module in imported Javascript resource

I like to access a registered QObject from within an imported js resource (qml -> .js -> Module). Access from QML works, but using ".import" as explained in the docs from within the js file does not. Some related issues raise the impression it may work (another) or not.

Is it generally possible and how, only possible for certain modules, or not at all?

Code with the annotated output of the console outputs:

main.cpp

[...]
qmlRegisterSingletonInstance<MyModule>("org.example.MyModule", 1, 0, "MyModule", (new MyModule()));
[...]

MyModule.hpp

#pragma once
#include <QObject>
class MyModule : public QObject
{
    Q_OBJECT
public:
    enum SOMETHING { AAA, BBB, CCC, DDD, EEE, FFF };
    Q_ENUM(SOMETHING)
};

main.qml

import org.example.MyModule 1.0
import "qrc:/something.js" as Something
[...]
console.log(MyModule, MyModule.DDD)// prints something like: "MyModule(0x....) 3"
[...]
Something.doit()
[...]

something.js

.import org.example.MyModule 1.0 as MyModule
[...]
console.log(MyModule, MyModule.DDD) // prints something like: "[object Object] undefined"
[...]

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Got an answer from support: Apparently, you need to prefix the Module with the import namespace, i.e. MyModule.MyModule.DDD instead of MyModule.DDD:

.import org.example.MyModule 1.0 as MyModule
[...]
console.log(MyModule.MyModule, MyModule.MyModule.DDD)
[...]
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!