QML 两种读资源方式

1. 通过文件路径读取

  1.1设置import path  main.cpp

    qputenv("QML2_IMPORT_PATH", "../qml1");  
     //或者
    //engine.addImportPath("../qml1/");

  1.2 添加file:调用

    Image {
      id: names
      source: "file:../images/First.png"
    }

2.通过qrc添加资源

  2.1 新建文件,选择qrc文件

  2.2 右键资源文件比如icon.qrc,选择open in editor

  2.3 选择Add Prefix和Add FIles

  在qml文件中使用RUL:调用,

imgSrc : "qrc:/icon/Icon/Icecream.png"

   右键目标资源文件,比如start.png,有copy url,可以直接复制URL地址出来

  

原文地址:https://www.cnblogs.com/gongkiro/p/13471522.html