OlivierLDff / Qaterial

🧩 Collection of Material Components based on QtQuickControls2.
https://olivierldff.github.io/Qaterial/
MIT License
320 stars 60 forks source link

Add Qaterial to existing Qt-Project using universal styled custom controls #136

Closed MichaelHeiser closed 2 years ago

MichaelHeiser commented 2 years ago

Hey,

I want to use Qaterial as main UI components in my applications. The application currently relies on a Universal styled custom control set. I managed to build Qaterial for Qt 5.15 and I also can build my application against it. App launches, but app crashes after loading my main qml file. I built qaterial on local hard drive and want to include the lib in my qmake base project.

Here my project file:

# set path and name of lib
CONFIG(debug, debug|release) {
    QAT_BUILDTYPE = Debug
}
else {
    QAT_BUILDTYPE = Release
}

#CONFIG += staticlib

DEFINES += "QATERIAL_STATIC=1"

*msvc*{
    INCLUDEPATH += $$PWD/../../../../Qaterial/install/win/$${QAT_BUILDTYPE}/include
    LIBS += -L$$PWD/../../../../Qaterial/install/win/$${QAT_BUILDTYPE}/lib \
    -lQaterial \
    -lQaterialIcons \
    -lQaterialFonts \
    -lQaterialComponents \
    -lQOlm
    DEPENDPATH += $$PWD/../../../../Qaterial/install/win/$${QAT_BUILDTYPE}/lib
    QML_IMPORT_PATH += $$PWD/../../../../Qaterial/qml/Qaterial
}

Load main file, in main file i did not import Qaterial. m_qmlEngine.load(QUrl(QStringLiteral("qrc:/EuroSoftLiveViewQml_win.qml")));

Init qaterial:

    m_engine->addImportPath("qrc:///");
    qaterial::loadQmlResources();
    qaterial::registerQmlTypes();

Starting app:

qaterial.utils: Load Qaterial v1.4.6 qaterial.utils: Load font ":/Qaterial/Fonts/Lato/Lato-Regular.ttf" qaterial.utils: Load font ":/Qaterial/Fonts/Roboto/Roboto-Medium.ttf" qaterial.utils: Load font ":/Qaterial/Fonts/Roboto/Roboto-Regular.ttf" qaterial.utils: Load font ":/Qaterial/Fonts/RobotoMono/RobotoMono-Regular.ttf"

Crash of app: image

I've been able to use locally built Qaterial with QaterialGallery and HelloWorldExample, these applications start fine. So my idea is that my config in qtquickcontrolsconfig2.conf could be the reason?

[Controls]
Style=Universal

[Material]
Primary=#03A9F4
Accent=#01579B

[Universal]
Accent=#0086E6

Can anyone help me?

OlivierLDff commented 2 years ago

Hello you should simply use cmake, I don't know qmake. I have no idea from where the crash might come.

MichaelHeiser commented 2 years ago

Hello same behaviour.

Here parts of my cmake. Luckily I'm currently working on moving my prject from qmake 2 cmake.

if(MSVC)
    include_directories(D:/Projects/Qt/Qaterial/install/win/${CMAKE_BUILD_TYPE}/include)
    target_link_directories(${QATERIALGALLERY_TARGET} PRIVATE D:/Projects/Qt/Qaterial/install/win/${CMAKE_BUILD_TYPE}/lib)
    set(QML_IMPORT_PATH D:/Projects/Qt/Qaterial/qml/Qaterial D:/Projects/Qt/Qaterial/install/win/${CMAKE_BUILD_TYPE}/lib CACHE STRING "" FORCE)
endif()

target_link_libraries(EuroSoft_live PRIVATE
        ${CMAKE_CURRENT_BINARY_DIR}/../../applets/measurement/measurement.lib
        ${CMAKE_CURRENT_BINARY_DIR}/../../applets/settings/settings.lib
        ${CMAKE_CURRENT_BINARY_DIR}/../../libraries/EuroSoft/EuroSoft.lib
        ${CMAKE_CURRENT_BINARY_DIR}/../../libraries/EuroSoftUi/EuroSoftUi.lib
        ${CMAKE_CURRENT_BINARY_DIR}/../../libraries/3rdparty/QCustomPlot/QCustomPlot.lib
        ${CMAKE_CURRENT_SOURCE_DIR}/../../libraries/3rdparty/QuickDownload/lib/win/QuickDownload${LIB_SUFFIX}.lib
        ${CMAKE_CURRENT_SOURCE_DIR}/../../libraries/3rdparty/SCodes/lib/win/SCodes${LIB_SUFFIX}.lib
        ${CMAKE_CURRENT_SOURCE_DIR}/../../libraries/3rdparty/S6600RemoteDisplay/lib/win/S6600RemoteDisplay${LIB_SUFFIX}.lib
        ${CMAKE_CURRENT_SOURCE_DIR}/../../libraries/3rdparty/ncreport/lib/win/NCReport${LIB_SUFFIX}2.lib
        ${CMAKE_CURRENT_SOURCE_DIR}/../../libraries/3rdparty/ncreport/lib/win/NCReportZint${LIB_SUFFIX}2.lib
        Qt::PrintSupport
        Qt::WebChannel
        SetupAPI
        hid
        user32
        opengl32.lib
        Qaterial
        QaterialIcons
        QaterialFonts
        QaterialComponents
        QOlm
    )
MichaelHeiser commented 2 years ago

When i don' add import path "qrc:///" I get following error:

qaterial.utils: Load font ":/Qaterial/Fonts/Roboto/Roboto-Medium.ttf"
qaterial.utils: Load font ":/Qaterial/Fonts/Roboto/Roboto-Regular.ttf"
qaterial.utils: Load font ":/Qaterial/Fonts/RobotoMono/RobotoMono-Regular.ttf"
QQmlApplicationEngine failed to load component
qrc:/EuroSoftLiveViewQml_win.qml:30:1: Type Framework.EsApplication unavailable
qrc:/ui/framework/EsApplication.qml:25:1: Type Controls.ApplicationWindow unavailable
qrc:/Qaterial/ApplicationWindow.qml:45:3: Qaterial.DialogLoader is not a type
WARNING: No translated disclaimer found. Using english disclaimer instead.

My application makes heavy usage of quickcontrols, could it be that loading qaterial "overwrites" quickcontrols object?

Regards Michael

OlivierLDff commented 2 years ago

Maybe here: https://github.com/OlivierLDff/Qaterial/blob/598a80f89777d79e80efe23bf5faada46218a703/src/Qaterial/Details/Utils.cpp#L139-L143

MichaelHeiser commented 2 years ago

Thank you very much!! This did the trick!!

m_engine->addImportPath("qrc:///");
qaterial::loadQmlResources(false);
qaterial::registerQmlTypes();

With this init without setting the style my app starts up.