Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Error - QML Image: Cannot open: url
Forum Updated to NodeBB v4.3 + New Features

Error - QML Image: Cannot open: url

Scheduled Pinned Locked Moved Solved QML and Qt Quick
14 Posts 3 Posters 1.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Anton1978A Offline
    Anton1978A Offline
    Anton1978
    wrote on last edited by Anton1978
    #1

    Good afternoon.
    There is an error adding the image source from the resource file.
    If I specify a file on disk as the source, then there is no problem.
    But such an application cannot be transferred to other computers.
    What's the matter?

    Image{
            anchors.fill: parent
           //source: "qrc:/pixmap/dice.png" //error - qrc:/qt/qml/Game01/Dice.qml:26:17: QML Image: Cannot open: qrc:/pixmap/dice.png
             source: "file:E:\\QML\\Game01\\dice.png" // it's ok
        }
    

    screen

    1 Reply Last reply
    0
    • Anton1978A Anton1978

      it works, but I don't understand why?
      What's wrong with the resource file?
      This works great in QWidget.

      and when assembling webassembly, there are no pictures again, although there is no error.
      And I really want this to be cross-platform.

      GrecKoG Offline
      GrecKoG Offline
      GrecKo
      Qt Champions 2018
      wrote on last edited by
      #8

      @Anton1978 said in Error - QML Image: Cannot open: url:

      it works, but I don't understand why?
      What's wrong with the resource file?

      Because the RESOURCES parameter of qt_add_qml_module needs actual files and will generate the qrc automatically. It's not meant to work with .qrc files. Read the doc.

      This works great in QWidget.

      I doubt qt_add_qml_module works great with QWidgets.

      and when assembling webassembly, there are no pictures again, although there is no error.
      And I really want this to be cross-platform.

      That's another problem.

      1 Reply Last reply
      1
      • GrecKoG Offline
        GrecKoG Offline
        GrecKo
        Qt Champions 2018
        wrote on last edited by
        #2

        The qrc:/pixmap/dice.png is likely not the correct one.
        Are you using CMake macro qt_add_qml_module?. Depending on your CMake projects, the default RESOURCE_PREFIX can be /qt/qml so the url would then be qrc:/qt/qml/pixmap/dice.png.

        1 Reply Last reply
        0
        • Anton1978A Offline
          Anton1978A Offline
          Anton1978
          wrote on last edited by
          #3

          Yes, I'm using qt_add_qml_module.
          Here's how it's implemented

          qt_add_qml_module(appGame01
              URI Game01
              VERSION 1.0
              QML_FILES
                  Main.qml
                  QML_FILES Game.qml
                  QML_FILES
                  SOURCES gamecalulate.h gamecalulate.cpp
                  QML_FILES
                  QML_FILES Dice.qml
                  RESOURCES Res.qrc
          )
          

          qrc:/qt/qml/pixmap/dice.png. - not worck

          1 Reply Last reply
          0
          • GrecKoG Offline
            GrecKoG Offline
            GrecKo
            Qt Champions 2018
            wrote on last edited by
            #4

            Your pixmap might be in qrc://Game01/pixmap/dice.png
            What's in Res.qrc?
            Also you could see what's in your resources files with the following snippet:

             QDirIterator it(":/", QDirIterator::Subdirectories);
             while (it.hasNext()) 
                qDebug() << it.nextFileInfo();
            
            1 Reply Last reply
            0
            • Anton1978A Offline
              Anton1978A Offline
              Anton1978
              wrote on last edited by Anton1978
              #5

              qrc://Game01/pixmap/dice.png not worck too
              Res.qrc - Qt resource file, I added it manually and created a pixmap prefix in it, and later added images to the resource file.

              And this code not found dice.png, Res.qrc only.

              GrecKoG 1 Reply Last reply
              0
              • Anton1978A Anton1978

                qrc://Game01/pixmap/dice.png not worck too
                Res.qrc - Qt resource file, I added it manually and created a pixmap prefix in it, and later added images to the resource file.

                And this code not found dice.png, Res.qrc only.

                GrecKoG Offline
                GrecKoG Offline
                GrecKo
                Qt Champions 2018
                wrote on last edited by
                #6

                @Anton1978 said in Error - QML Image: Cannot open: url:

                And this code not found dice.png, Res.qrc only.

                That's because the RESOURCES parameter in qt_add_qml_module directly adds the listed files to the target's resources. Just list your dice.png here.
                If you want to use a .qrc file use the qt_add_resources CMake function.

                1 Reply Last reply
                1
                • Anton1978A Offline
                  Anton1978A Offline
                  Anton1978
                  wrote on last edited by Anton1978
                  #7

                  it works, but I don't understand why?
                  What's wrong with the resource file?
                  This works great in QWidget.

                  and when assembling webassembly, there are no pictures again, although there is no error.
                  And I really want this to be cross-platform.

                  GrecKoG 1 Reply Last reply
                  0
                  • Anton1978A Anton1978

                    it works, but I don't understand why?
                    What's wrong with the resource file?
                    This works great in QWidget.

                    and when assembling webassembly, there are no pictures again, although there is no error.
                    And I really want this to be cross-platform.

                    GrecKoG Offline
                    GrecKoG Offline
                    GrecKo
                    Qt Champions 2018
                    wrote on last edited by
                    #8

                    @Anton1978 said in Error - QML Image: Cannot open: url:

                    it works, but I don't understand why?
                    What's wrong with the resource file?

                    Because the RESOURCES parameter of qt_add_qml_module needs actual files and will generate the qrc automatically. It's not meant to work with .qrc files. Read the doc.

                    This works great in QWidget.

                    I doubt qt_add_qml_module works great with QWidgets.

                    and when assembling webassembly, there are no pictures again, although there is no error.
                    And I really want this to be cross-platform.

                    That's another problem.

                    1 Reply Last reply
                    1
                    • Anton1978A Offline
                      Anton1978A Offline
                      Anton1978
                      wrote on last edited by
                      #9

                      Ok, this is strange, but this solves the problem

                      1 Reply Last reply
                      0
                      • Anton1978A Anton1978 has marked this topic as solved on
                      • Anton1978A Offline
                        Anton1978A Offline
                        Anton1978
                        wrote on last edited by
                        #10

                        oh my god, and again

                        qt_add_resources(appTest05 "res"
                            #PREFIX "/res"
                            FILES res/cube_001_mesh.mesh res/heaven.png
                        )
                        

                        This is what I get - where are the two folders from?
                        wtf
                        And in QML

                                Model {
                                    id: cube
                                    objectName: "Cube"
                                    rotation: Qt.quaternion(0.707107, -0.707107, 0, 0)
                                    scale: Qt.vector3d(100, 100, 100)
                                    source: "qrc://Test05/res/cube_001_mesh.mesh" //it work
                                    materials: [
                                        defaultMaterial_material
                                    ]
                                }
                        

                        and

                        environment: SceneEnvironment{
                                    clearColor: "#222222"
                                    backgroundMode: SceneEnvironment.SkyBox
                                    lightProbe: Texture{
                                        source: "qrc:\res\heaven.png" //not worck
                                        source: "qrc://Test05/Resources/res/heaven.png" //not worck
                                    }
                                    probeExposure: 0.75
                                }
                        

                        I really don’t understand - now what?

                        1 Reply Last reply
                        0
                        • GrecKoG Offline
                          GrecKoG Offline
                          GrecKo
                          Qt Champions 2018
                          wrote on last edited by
                          #11

                          What's your question? Why would the 2 last urls work?
                          Do you expext the 3 different versions to work the same?

                          https://doc.qt.io/qt-6/qt-add-resources.html#arguments-of-the-target-based-variant

                          1 Reply Last reply
                          0
                          • Anton1978A Offline
                            Anton1978A Offline
                            Anton1978
                            wrote on last edited by
                            #12

                            I wrote three versions to make it clear how I tried to fix this
                            source: "qrc://Test05/res/heaven.png" - not work to

                            1 Reply Last reply
                            0
                            • A Offline
                              A Offline
                              ankou29666
                              wrote on last edited by
                              #13

                              normally you write ":/path/to/resource" or "qrc:/path/to/ressource".
                              You should use a single / after qrc: not "qrc://"

                              1 Reply Last reply
                              0
                              • Anton1978A Offline
                                Anton1978A Offline
                                Anton1978
                                wrote on last edited by
                                #14

                                surprising, but it turned out to be correct qrc:\res\heaven.png
                                Why ?

                                1 Reply Last reply
                                0

                                • Login

                                • Login or register to search.
                                • First post
                                  Last post
                                0
                                • Categories
                                • Recent
                                • Tags
                                • Popular
                                • Users
                                • Groups
                                • Search
                                • Get Qt Extensions
                                • Unsolved