0

I want to build a library of some of the common classes/functions and (hopefully) QML components that I've made between projects.

I created a Shared Library and have the classes/functions loading properly, but when I try to include a QML file it says "qrc:/main.qml:4:1: "../SharedLib/QMLFiles": no such directory" (but it does exist).

Do I have to do something else to use a Shared Libraries QML files in another project, or is this just not possible right now?

This is the QML file for my project (not the shared library).

import QtQuick 2.10
import QtQuick.Window 2.10

import "../SharedLib/QMLFiles"

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

    SharedComponent {

    }
}
Rick
  • 421
  • 3
  • 15
  • It looks like you're using Qt5. In Qt6, they heavily push the use of modules which is *supposed* to make this type of thing easier. Modules are still a thing in Qt5, but you have to do more things manually. Are your qml files in a resource file? – JarMan Jun 15 '23 at 16:34
  • @JarMan I am using Qt5. In the SharedLibrary they are in a filter titled QML (it auto added it there when I added a new QML file to the project). I'm not sure if I can add a resource file to the SharedLibrary can I? And if I can would that make the file importable from an external project? – Rick Jun 15 '23 at 18:30
  • You can create a resource file for a shared library. Did you look at [this](https://stackoverflow.com/questions/40968813/how-create-shared-library-in-qt-qml)? – JarMan Jun 15 '23 at 19:01
  • The way we organize a large application with reusable libraries if through the use of `git submodules`. This allows you to pick the version of the library you want to use, not necessarily the latest. As a submodule, it will appear as a pseudo subdirectory to your project, but, be managed in a different git repo with its own issue management and tracking. Because it appears as a submodule, you refer to it in your qrc as if it was part of your project. After you worked with this for a bit, you'll realize this process works really well with Qt/QML. – Stephen Quan Jun 19 '23 at 23:11
  • As an example of this, check out https://github.com/stephenquan/qt5-qml-promises-demo – Stephen Quan Jun 19 '23 at 23:12

0 Answers0