Important: Please read the Qt Code of Conduct -

QML and Qt compile problem

  • How to allows QML resource files to be stored as binary files in an application executable .My application executable is anpicture_viewer of mixed QML/c++ .I have made a resource file ,the errror is cann't fonud displaied pictures.

  • Please share more information about the errors by showing the build issues and the compile output.

  • Resource files are the way to go. If you have issues with files that are not found, you are not setting your paths correctly.

  • my error is qrc:/qml/qmlevolution/PicturePathviewDelegate.qml:19:9: QML Image: Cannot open: qrc:/home/user/MyDocs/DCIM/png/320_50633_fe167344f5c3eb3.png

    my picture path is /home/user/MyDocs/DCIM/png

    the picture displaied normal when there is no resource file

  • You mean that inside your resource file, you use the /home/user/MyDocs/DCIM/png/ path?! That path looks suspiciously like a local file path.

    Personally, I'd just use something like images/ as the path in my qrc.

    Could you show us the contents of your .qrc file please?

  • my icon of png can display but the picture_viewer application executable can't display nesssary pictures in /home/user/MyDocs/DICM/png

    <qresource prefix="/">

    [[marked up code, Tobias]]

  • The problem is quite obvious then, I think:

    You are trying to load an image file with the :/home/user/MyDocs/DCIM/png/320_50633_fe167344f5c3eb3.png path, but that path does not exist in your resource.

    You should use relative paths in your qml files. That prevents issues like these. On top of that, I would suggest you group your files properly. That is: you put images in a separate directory. That is just a style issue though.

  • I don.t want :/home/user/MyDocs/DCIM/png/320_50633_fe167344f5c3eb3.png as icon
    Though I don't add the directory in resource file ,the error is the directory automaticly added qrc
    I use QDir to load and scan /home/user/MyDocs/DCIM/png/
    the code as fellow

    m_pictureFolder = new PictureFolder("/home/user/MyDocs/DCIM/png");

    PictureFolder::PictureFolder(const QString workDir)
    m_qListPicture = new QList<Picture>;
    QStringList filters;
    foreach(QByteArray format, QImageReader::supportedImageFormats())
    filters += "." + format;

    void PictureFolder::imageScan(const QString &path,const QStringList &filters/, QTextStream &out/)
    QDir pictureDir(path);

    foreach(QString file, pictureDir.entryList(filters,QDir::Files))
        *m_qListPicture << Picture(file,"comments here:");/*生成了一个图片对象*/
    foreach(QString subDir, pictureDir.entryList(QDir::Dirs|QDir::NoDotAndDotDot))
        imageScan(path + QDir::separator() + subDir, filters/*,out*/);


    Edit: please use @ tags around code sections for proper highlighting; Andre

  • I hava find the problem Thanks because I didn't add 'file://' ahead picture path
    it is an protocol of QUrl

Log in to reply