Results 1 to 2 of 2

Thread: Can’t load the image after I register the qml file to Qt resource system

  1. #1
    Join Date
    Jan 2011
    Posts
    127
    Thanks
    42
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Can’t load the image after I register the qml file to Qt resource system

    main.qml

    Qt Code:
    1. import QtQuick 2.0
    2.  
    3. Rectangle {
    4. width: 360
    5. height: 360
    6.  
    7. Image{
    8. anchors.fill: parent
    9. source: "/Pictures/img_0000.jpg"
    10. }
    11. }
    To copy to clipboard, switch view to plain text mode 

    main.cpp
    Qt Code:
    1. #include <QtGui/QGuiApplication>
    2. #include "qtquick2applicationviewer.h"
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QGuiApplication app(argc, argv);
    7.  
    8. QtQuick2ApplicationViewer viewer;
    9. //viewer.setMainQmlFile(QStringLiteral("qml/qmlResource/main.qml"));
    10. viewer.setSource(QStringLiteral("qrc:///qml/qmlResource/main.qml"));
    11. viewer.showExpanded();
    12.  
    13. return app.exec();
    14. }
    To copy to clipboard, switch view to plain text mode 

    error message

    qrc:///qml/qmlResource/main.qml:7:5: QML Image: Cannot open: qrc:///Pictures/img_0000.jpg

    looks like the Image complain it can not find the image from qrc
    but I don’t want the program to load the image from qrc
    it is not my intention


    Added after 28 minutes:


    Find the answer
    http://qt-project.org/forums/viewthread/10477
    Last edited by stereoMatching; 17th June 2013 at 04:01.

  2. #2
    Join Date
    Jan 2011
    Posts
    127
    Thanks
    42
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Can’t load the image after I register the qml file to Qt resource system

    just add "file:///" before "/Pictures/img_0000.jpg"
    after you register main.qml into qrc list
    every image you load will prepend "qrc://" so the program would
    assume the image is located inside your binary
    prepend "file:///" could tell the program "this file do not reside in the binary"

Similar Threads

  1. How to load icons from resource file
    By joseph in forum Qt Programming
    Replies: 7
    Last Post: 25th June 2012, 07:00
  2. Cannot register Service name on System Bus
    By drf in forum Qt Programming
    Replies: 1
    Last Post: 19th April 2012, 02:44
  3. problem about load resource file dynamically
    By Raul in forum Qt Programming
    Replies: 1
    Last Post: 27th August 2010, 05:56
  4. How can Stylesheet reference non resource image file
    By dpatel in forum Qt Programming
    Replies: 1
    Last Post: 23rd April 2010, 08:41
  5. QPainter.drawImage() not working with resource image file
    By thiagoalencar22 in forum Qt Programming
    Replies: 4
    Last Post: 22nd April 2010, 21:07

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.