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

How to open other QML files in main.qml (error: no such file or directory)



  • Hello!

    According to this article I am not using *.qrc files. Instead of it I have in my *.pro file this peace of code:

    RESOURCES += \
        app/qtquickcontrols2.conf \
        app/main.qml \
        $$files(app/pages/*.qml) \
        $$files(app/widgets/*.qml)
    

    In result I have very neat Project view without any Resources level...
    neat project view

    but here is the problem! In main.c this works perfectly:

    const QUrl url(QStringLiteral("qrc:/app/main.qml"));
    

    but in main.qml this is problem:

    StackView {
        id: stackView
        initialItem: "pages/HomeFrom.ui.qml"     // I've tried "app/pages/HomeFrom.ui.qml" and just "HomeFrom.ui.qml" too :-) 
        anchors.fill: parent
    }
    

    Specifically it is this error:

    W libFaceHasherExh_x86.so: qrc:/app/main.qml:64:5: QML StackView: initialItem: qrc:/app/pages/HomeFrom.ui.qml:-1 No such file or directory
    

    Can you please tell what am I doing wrong? Thank you very much!

    PS: I almost forgot... this is showing in my General messages. Do you know what is means?

    /home/frantisek/Tools/Qt/5.15.0/android/mkspecs/features/android/android_deployment_settings.prf(78): contains(): Encountered invalid regular expression '.*\qmake_qmake_immediate.qrc$'.
    

  • Moderators

    I think the issue may be that you wrote HomeFrom instead of HomeForm 😜


    Edit:
    Protip to prevent such typos: Right click in your project tree on the target file, select copy path or copy url and simply paste it in your code edit sniped by @sierdzio 😉


  • Moderators

    @fpartl said in How to open other QML files in main.qml (error: no such file or directory):

    According to this article I am not using *.qrc files

    Quoting from that article:

    This can be inefficient, especially for large sets of files. In this case, a better approach is to separate each type of resource into its own .qrc file

    Anyway, coming to your problem:

    initialItem: "pages/HomeFrom.ui.qml" // I've tried "app/pages/HomeFrom.ui.qml" and just "HomeFrom.ui.qml" too :-)

    It's always a trial and error thing with QRC and QML :-D A few other things to try:

    • ":/app/pages/HomeFrom.ui.qml"
    • ":/pages/HomeFrom.ui.qml"
    • "qrc:///app/pages/HomeFrom.ui.qml"
    • "qrc:///pages/HomeFrom.ui.qml"

    PS: I almost forgot... this is showing in my General messages. Do you know what is means?

    I may be misremembering something but I think updating to Qt 5.15.1 fixes this issue.



  • @sierdzio do you think 12 files is "large set of files"? Alright, I hope for slightly quicker build while changing my .pro file to this :-)

    # QML resources
    qml_pages.files = $$files(*qml)
    qml_pages.prefix = /qml/pages
    
    qml_widgets.files = $$files(*.qml)
    qml_widgets.prefix = /qml/widgets
    
    RESOURCES += \
        qml/qtquickcontrols2.conf \
        qml/main.qml \
        qml_pages \
        qml_widgets
    

    Using your shotgun debugging method I've come to this results :-D

    ":/qml/pages/HomeFrom.ui.qml"              # invalid url: :/qml/pages/HomeFrom.ui.qml
    ":/pages/HomeFrom.ui.qml"                  # invalid url: :/pages/HomeFrom.ui.qml
    "qrc:///qml/pages/HomeFrom.ui.qml"         # initialItem: qrc:/qml/pages/HomeFrom.ui.qml:-1 No such file or directory
    "qrc:///pages/HomeFrom.ui.qml"             # initialItem: qrc:/pages/HomeFrom.ui.qml:-1 No such file or directory
    

    Do you have any other suggestions? It annoys me that I end up on such a basic thing... Thank you for your help.

    PS: After using resources.files stuff my Project view looks exacly the same (I've just renamed app to qml). :-)
    Project view

    PS2: Maybe it could help if I show you my build settings. I am not sure the rcc is called but as I wrote in the main.cpp the file is found... :-/
    Build settings


  • Moderators

    I think the issue may be that you wrote HomeFrom instead of HomeForm 😜


    Edit:
    Protip to prevent such typos: Right click in your project tree on the target file, select copy path or copy url and simply paste it in your code edit sniped by @sierdzio 😉


  • Moderators

    @fpartl said in How to open other QML files in main.qml (error: no such file or directory):

    Do you have any other suggestions? It annoys me that I end up on such a basic thing... Thank you for your help.

    PS: After using resources.files stuff my Project view looks exacly the same (I've just renamed app to qml). :-)
    Project view

    You can right-click on any QML file and select "Copy URL" or "Copy Path" - Qt Creator will automatically provide you with a correct path.



  • @sierdzio said in How to open other QML files in main.qml (error: no such file or directory):

    You can right-click on any QML file and select "Copy URL" or "Copy Path" - Qt Creator will automatically provide you with a correct path.

    I do not have this option in my context menu when I click on any .qml file. :-/ I have the last version of QtCreator.


  • Moderators

    @fpartl

    I have the "last" version of QtC as well, its definitely there
    47144744-f806-4539-9cdc-bcfb1ca9984e-image.png

    may only be the case, if the file is inside your resource file/system 🤷‍♂️ Haven't checked that


  • Moderators

    This post is deleted!


  • @J-Hilk OMG I am such an idiot... 4 hours of Googling... :D Thank you for saving my life! In conclusion of others the original code I've posted is not working only because of this typing laxity.


Log in to reply