Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QML Styling in Hybrid C++/QML application



  • Hi, Currently, we are on Qt 5.15.5. We have a hybrid application with a good bit of C++ code (80%) & some panes are QML (20%) that are read in at run-time. I'm trying to get some basic styling working. I have kept it simple to start with to aim to get it working with one case. Everytime I "import Style 1.0 Style.qml", it doesn't work & the QML is not loaded to display. I have a QML directory, within which I have Style.qml (just QtObject { property color textColor: "black" }), app_qml.qrc for resource file, quickcontrols2.conf (referencing Material), & a qmldir called module Style with Style 1.0 Style.qml. I have the QML imported, I am building with the QRC definition in the .pro file, but if I do import Style 1.0 Style.qml, then the QML file in which it is imported fails to load with a reference error. I have tried & played with different things, but the problem persists. I just want to do simple styling such as text color & so forth that can be referenced in the QML file, but so far it is not working. Perhaps someone has a suggestion.



  • hi
    i would suggest simplifying the question if possible
    also see https://wiki.qt.io/Qml_Styling



  • @ODБOï I have already read that & followed, but still not working. There's something missing in the instructions -- it is incomplete.



  • @SocketSackett said in QML Styling in Hybrid C++/QML application:

    There's something missing in the instructions

    What exactly ?

    Can you simplify you question, show us what exactly are you doing and what is the error ?



  • @SocketSackett
    This might be due to QmlEngine failed to see where the qmldir is.

    here is my blog post and example of how to create a shared QML component library.
    https://arunpkqt.wordpress.com/2020/07/25/shared-qml-component-library/

    We need to also pass the path to qmldir to the QQmlEngine to search for the installed modules. This path may be a local filesystem directory, a Qt Resource path (:/imports), a Qt Resource url (qrc:/imports) or a URL. As we have already included the qrc file in aforementioned step we could use
    
    1
    engine.addImportPath(":/imports");
    4. In the QML file import the module as
    
    1
    import com.apk.components 1.0 as Apk
    

    hope that helps!


Log in to reply