[Qt-creator] QML dir hierarchy

Wingard, Alexander alexander.wingard at crosscontrol.com
Wed Jan 4 18:55:18 CET 2017


That can absolutely be done.

Made a quick example:

// This is how the qrc is structured
Qml.qrc
=======
 <RCC>
    <qresource prefix="/">
        <file>main.qml</file>
    </qresource>
    <qresource prefix="/assets">
        <file>MyAsset.qml</file>
    </qresource>
    <qresource prefix="/images">
        <file>alert.png</file>
    </qresource>
</RCC>

// And this is how you can address components under prefixes
Main.qml
==========
import QtQuick 2.1
import QtQuick.Controls 1.0
import "qrc:/assets"  // NEEDED FOR COMPONENTS UNDER PREFIXES!

ApplicationWindow {
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")

    MyAsset {
        // Available due to the explicit import of qrc:/assets
        anchors.centerIn: parent
    }

    Image {
        // Path pattern:   "qrc:<prefix>/< path>"
        // Tip: You can use aliases in qml.qrc to shorten paths for files in subfolders.
        source: "qrc:/images/alert.png"
    }
}

Hope that helped!
/Alex


Alexander WingÄrd
Software Developer
www.crosscontrol.com

CrossControl
making machines smart, safe and productive


-----Original Message-----
From: Qt-creator [mailto:qt-creator-bounces+alexander.wingard=maximatecc.com at qt-project.org] On Behalf Of Jason H
Sent: den 4 januari 2017 16:44
To: interestqt-project.org; qt-creator
Subject: [Qt-creator] QML dir hierarchy

I am cross posting this to QtC and Interest because it's a combinational issue.

My QML projects are getting sizable, I'd like to start breaking my QML resources down in a hierarchy, but my attempt at that has failed.
Given:

qml.qrc /
- app.js
- Screen1.qml
- Component1.qml
- Screen1.qml
- Component3.qml
- Component4.qml
- Screen1.qml
- Component2.qml

I'd like to break it down into:
qml.qrc /
- Screens /
-- Screen1.qml
-- Screen1.qml
-- Screen1.qml
- Components /
-- Comoponent1.qml
-- Comoponent2.qml

But I was not able to accomplish this in QtC. So I hacked the QRC file to have two prefix entries:  <qresource prefix="/screens"> and  <qresource prefix="/components"> However this resulted in errors.

Also, in QtC they weren't folderized, they just appeared as screens/Screen1.qml ...
components/Component1.qml
...

How can I accomplish a folderized QRC? Currently, the filesystem is flat, but I don't mind adding them to actual folders if that would help.
_______________________________________________
Qt-creator mailing list
Qt-creator at qt-project.org
http://lists.qt-project.org/mailman/listinfo/qt-creator

________________________________

Actuant Corporation Email Notice

This message is intended only for the use of the Addressee and may contain information that is PRIVILEGED and/or CONFIDENTIAL.
This email is intended only for the personal and confidential use of the recipient(s) named above. If the reader of this email is not an intended recipient, you have received this email in error and any review, dissemination, distribution or copying is strictly prohibited.
If you have received this email in error, please notify the sender immediately by return mail and permanently delete the copy you received.

Thank you.



More information about the Qt-creator mailing list