Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Support Qt Designer #78

Open
ochagnon opened this issue Oct 19, 2020 · 20 comments
Open

✨ Support Qt Designer #78

ochagnon opened this issue Oct 19, 2020 · 20 comments

Comments

@ochagnon
Copy link

ochagnon commented Oct 19, 2020

Warning: I'm not familiar with cmake, my experience had been with qmake so far. My question will probably be asked again and again, as QT Creator is a popular IDE for Qt/QML applications.

I'm trying to use Qaterial with QTCreator. In this Github repo, I provide the code I use to reproduce this problem, with 1 commit per change I perform. You can very easily try yourself.

So, I start from scratch and create a Test project that use cmake. This commit just the initial output of Qt Creator.

Then, I add this commit that switch C++ and QML to Qaterial and add dependency build.

But, that don't works, build fail with

Test/main.cpp:1:10: fatal error: 'Qaterial/Qaterial.hpp' file not found
#include <Qaterial/Qaterial.hpp>
         ^~~~~~~~~~~~~~~~~~~~~~~
1 error generated.

Sure, the reason is those files are in build-Test-Desktop_Qt_5_15_1_clang_64bit-Debug/_deps/qaterial-src/.

From QtCreator cmake integration doc:

Adding External Libraries to CMake Projects
Through external libraries, Qt Creator can support code completion and syntax highlighting as if they were part of the current project or the Qt library.
Qt Creator detects the external libraries using the find_package() macro. Some libraries come with the CMake installation. You can find those in the Modules directory of your CMake installation. For more information, see cmake-packages(7).
Syntax completion and highlighting work once your project successfully builds and links against the external library.

So, I tried find_package(Qaterial) and output of cmake is:

Make Warning at CMakeLists.txt:38 (find_package):
  By not providing "FindQaterial.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "Qaterial",
  but CMake did not find one.

  Could not find a package configuration file provided by "Qaterial" with any
  of the following names:

    QaterialConfig.cmake
    qaterial-config.cmake

  Add the installation prefix of "Qaterial" to CMAKE_PREFIX_PATH or set
  "Qaterial_DIR" to a directory containing one of the above files.  If
  "Qaterial" provides a separate development package or SDK, be sure it has
  been installed.

In Qaterial repository, there is no *config*.cmake nor Find*.cmake.

So, how can I use Qaterial with Qt Creator?

@ochagnon
Copy link
Author

ochagnon commented Oct 19, 2020

In this commit I solve the C++ side of the problem.

Now it build and link and run:

QQmlApplicationEngine failed to load component
qrc:/main.qml:3:1: Qaterial.ApplicationWindow is not a type

But , that is a bit weird, shouldn't that just work? because in main.cpp, there is:

    qaterial::loadQmlResources();
    qaterial::registerQmlTypes();

@ochagnon
Copy link
Author

@ochagnon ochagnon reopened this Oct 19, 2020
@ochagnon
Copy link
Author

So, the binary start and can load QML, but the UI of Qt creator still complains that QML module not found (Qaterial)

@OlivierLDff
Copy link
Owner

Ok, so for now all your problems are not related to qt creator but to cmake (which are the one everyone is struggling with starting with cmake)
I saw your code and I Will investigate. It is strange since you added the addImportPath

@ochagnon
Copy link
Author

@OlivierLDff thanks, this doc give a few possible fixes for the missing qml in creator itself, I'm also investigating

@OlivierLDff
Copy link
Owner

You should use https://github.com/OlivierLDff/QaterialGallery as a reference

@ochagnon
Copy link
Author

ochagnon commented Oct 19, 2020

I fixed QT Creator in ochagnon/qaterial-qtcreator-bug@18c4afd

@OlivierLDff
Copy link
Owner

OlivierLDff commented Oct 19, 2020

This kind of fix is ugly, because it is hard coded path. When deploying your app it will be a nightmare.
Anyway, qaterial's qml files should be embedded in qrc/Qaterial. And there should be a qrc/Qaterial/qmldir in there.

@ochagnon
Copy link
Author

This kind of fix is ugly, because it is hard coded path. When deploying your app it will be a nightmare.

that don't solve everything, there is additional issues

module: "Qaterial.Impl.Icons" is not installed

@ochagnon
Copy link
Author

Anyway, qaterial's qml files should be embedded in qrc/Qaterial. And there should be a qrc/Qaterial/qmldir in there.

how?

@ochagnon
Copy link
Author

Anyway, qaterial's qml files should be embedded in qrc/Qaterial. And there should be a qrc/Qaterial/qmldir in there.

I'm looking at gallery as a reference and I don't see an obvious command that embed Qaterial into the gallery

@OlivierLDff
Copy link
Owner

Yes because you are missing a file in qrc:/Qaterial/Impl/Icons which is only in qrc (because generated)

@OlivierLDff
Copy link
Owner

I opened your example on windows

git clone https://github.com/ochagnon/qaterial-qtcreator-bug
cd qaterial-qtcreator-bug
mkdir build
cd build/
cmake ..
cmake --build . -j

And the app launched.

Did you clean your cmake build folder?

@ochagnon
Copy link
Author

Yes because you are missing a file in qrc:/Qaterial/Impl/Icons which is only in qrc (because generated)

But, how can I add this resource with mine?

I don't see anything in this directory
There is no additional .qrc loaded in Main.cpp
I don't get any cmake build steps that combine project qml with the Qaterial dependencies :(

@OlivierLDff
Copy link
Owner

You shouldn't have anything to do, that is why it is strange.
image
For me it worked without any problem.
You should try to rm -rf * your build folder and do cmake .. again.

@OlivierLDff
Copy link
Owner

OlivierLDff commented Oct 19, 2020

demo qr creator2

@ochagnon
Copy link
Author

And the app launched.
Did you clean your cmake build folder?

yes, the application build and run, but the problem is when I try to open QtCreator designer (very important for development).

First, I had to add import QtQuick 2.12 to my Main.qml and:

Screen Shot 2020-10-19 at 15 14 56

This is where the missing icons error show up. This is probably because I don't use any icons at this point in my Main.qml. The very minimalistic things I tried to do don't trigger that error.

I tried with Gallery demo app, and I have an other problem.

Screen Shot 2020-10-19 at 15 04 09

@ochagnon
Copy link
Author

The problem is only in QtCreator in "Design" mode

@OlivierLDff
Copy link
Owner

I never used design, I know qaterial should be compiled as a plugin for it to work and there is special requirements.
Qaterial isn't only qml files.
Sorry I don't have time to support that on my free time since I'm not using it but feel free to create a pull request that address the issue

@OlivierLDff
Copy link
Owner

The file you are missing are located in your build folder res/Icons/Generated & res/Fonts/Generated

@OlivierLDff OlivierLDff changed the title CMake and QTCreator integration ✨ Support Qt Designer Oct 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants