0

I have an Android/IOS/Desktop Qt Widgets (Qt 6.5) application (C++) I am working on in Qt Creator. I liked the ease of using the Design/.ui editor that is built into Creator, but I wanted to try Qt Design Studio as well.

I made a new Stack-style project in Design Studio, and I built a relatively simple component (Screen01) with a few images and a text entry box and added it as a child to the Stack in App.qml. Right now I have the Screen01 component filling/anchoring to the Stack in App.qml.

The issue I am running into now is the "right" way to integrate that QML UI into my C++/widgets application.

The first few things I tried were to just immediately show the QML UI (App.qml) as some sort of component in mainwindow, or standalone/without even using mainwindow.

I tried QQuickView first (which I found information about from How to displaying QML file in widget). I tried adding a QQuickView widget to mainwindow and setting the child to app.qml/main.qml/screen01.qml.ui/etc... but ultimately would get an error: module "content" or module "MyProjectName" is not installed. I tried just removing the imports that were broken, and I was able to get the view to draw - it just had a lot of errors. One of the errors was: module "Constants" is not installed (I think Constants was just generated as part of the Design Studio project). I tried to just get past that by setting the values myself in App.qml/Screen01/etc, which did work; but then that caused all the anchors/layouts in the UI to be broken.

So I tried doing the same as above, but with a QQuickWidget. I got the same result.

I also tried making a QQMLEngine, and adding import paths to the QML project (I added .../MyProject, .../MyProject/content, .../MyProject/imports and "/"), but this didn't resolve the missing imports either.

After adding the import paths, I tried registering the module as well: QQMLEngine.registerModule

I did generate a CMakeLists.txt for the Design Studio project using File->Export->Generate CMake Build Files, and I was able to get about the same results there; I can draw the UI, but it is pretty broken/not responsive.

I think the bulk of what I am wanting to work out is how I can work on my QML UIs in Design Studio, then somehow take that project and just use it somehow in my C++/widgets app. I only really need the one UI, everything else I have is in widgets/that is the majority of what I have worked on.

Is this feasible/how could I get this to work correctly? Ideally I would just be showing the UI instead of the mainwindow, or alternatively adding the UI as some sort of widget/view to mainwindow and having it be the main widget.

I am building my c++ project using CMake.

0 Answers0