Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. unable to use images in QML

unable to use images in QML

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 213 Views
  • 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.
  • W Offline
    W Offline
    wiadro
    wrote on last edited by
    #1

    hi, i was attempting to learn to use images, but this simple code simply doesnt work for me, even tho i can see it in design studio. i get the following error
    qrc:/wtf/Main.qml:11:5: QML Image: Cannot open: qrc:/wtf/myimage.png15:2

    import QtQuick
    import QtQuick.Window
    
    Window {
        width: 640
        height: 480
        opacity: 0.6
        visible: true
        title: qsTr("Hello World")
    
        Image {
            id: image
            x: 270
            y: 139
            width: 100
            height: 100
            opacity: 1
            source: "myimage.png"
            fillMode: Image.PreserveAspectFit
        }
    }
    
    

    i also have a resource file ,which contains the png image with the same name as in the source declaration...

    any insights on what i could be doing wrong here?

    J.HilkJ 1 Reply Last reply
    0
    • W wiadro

      hi, i was attempting to learn to use images, but this simple code simply doesnt work for me, even tho i can see it in design studio. i get the following error
      qrc:/wtf/Main.qml:11:5: QML Image: Cannot open: qrc:/wtf/myimage.png15:2

      import QtQuick
      import QtQuick.Window
      
      Window {
          width: 640
          height: 480
          opacity: 0.6
          visible: true
          title: qsTr("Hello World")
      
          Image {
              id: image
              x: 270
              y: 139
              width: 100
              height: 100
              opacity: 1
              source: "myimage.png"
              fillMode: Image.PreserveAspectFit
          }
      }
      
      

      i also have a resource file ,which contains the png image with the same name as in the source declaration...

      any insights on what i could be doing wrong here?

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      @wiadro that is not the source code that produces the error message. because this : source: "myimage.png" is a relative path and does not refer to a resource file, like the error message says.


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      W 1 Reply Last reply
      1
      • J.HilkJ J.Hilk

        @wiadro that is not the source code that produces the error message. because this : source: "myimage.png" is a relative path and does not refer to a resource file, like the error message says.

        W Offline
        W Offline
        wiadro
        wrote on last edited by
        #3

        @J-Hilk what do i need to do, there is no other code besides main.qml which is in its default state.

        JoeCFDJ 1 Reply Last reply
        0
        • W wiadro

          @J-Hilk what do i need to do, there is no other code besides main.qml which is in its default state.

          JoeCFDJ Offline
          JoeCFDJ Offline
          JoeCFD
          wrote on last edited by
          #4
          This post is deleted!
          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