From 10:00 CET Friday 22nd November we will adjust how the server works to deal with some recently reported problems. Therefore there may be a load problem, if you experience more problems than usual trying to access the forum then please PM AndyS or any of the moderators so they can inform me.


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

    @
    <RCC>
    <qresource prefix="/">
    <file>qml/qmlevolution/main.qml</file>
    <file>qml/qmlevolution/1.png</file>
    <file>qml/qmlevolution/2.png</file>
    <file>qml/qmlevolution/add.png</file>
    <file>qml/qmlevolution/album.png</file>
    <file>qml/qmlevolution/back.png</file>
    <file>qml/qmlevolution/delete.png</file>
    <file>qml/qmlevolution/plus.png</file>
    <file>qml/qmlevolution/Qt.png</file>
    <file>qml/qmlevolution/rotation.png</file>
    <file>qml/qmlevolution/slide.png</file>
    <file>qml/qmlevolution/zoomIn.png</file>
    <file>qml/qmlevolution/zoomOut.png</file>
    <file>qml/qmlevolution/AlbumName.qml</file>
    <file>qml/qmlevolution/DisplayAlbumDescription.qml</file>
    <file>qml/qmlevolution/DisplayAlbumNameDelegate.qml</file>
    <file>qml/qmlevolution/DisplayAlbumNameMenu.qml</file>
    <file>qml/qmlevolution/HoldMenu.qml</file>
    <file>qml/qmlevolution/NewAlbumDialog.qml</file>
    <file>qml/qmlevolution/NQEButton.qml</file>
    <file>qml/qmlevolution/PictureGridView.qml</file>
    <file>qml/qmlevolution/PictureGridViewDelegate.qml</file>
    <file>qml/qmlevolution/PictureListView.qml</file>
    <file>qml/qmlevolution/PictureListViewDelegate.qml</file>
    <file>qml/qmlevolution/PicturePathView.qml</file>
    <file>qml/qmlevolution/PicturePathviewDelegate.qml</file>
    <file>qml/qmlevolution/SplashScreen.qml</file>
    <file>qml/qmlevolution/ToolBar.qml</file>
    <file>componentCreation.js</file>
    </qresource>
    </RCC>
    @

    [[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;
    imageScan(workDir,filters/
    ,out*/);
    }

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

    foreach(QString file, pictureDir.entryList(filters,QDir::Files))
    {
        file=pictureDir.absoluteFilePath(file);
        *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