Results 1 to 13 of 13

Thread: Source image problem and weird error - How and where add resource files?

  1. #1

    Default Source image problem and weird error - How and where add resource files?

    Hello QT community

    I am trying to learn QT Quick and using this online book http://qmlbook.org/ch01/index.html

    I do everything like they write till here: 1.2.2. Digesting an User Interface

    Where I code this:
    Qt Code:
    1. import QtQuick 2.0
    2.  
    3. Image {
    4. id: root
    5. source: "images/background.png"
    6. }
    To copy to clipboard, switch view to plain text mode 

    However nowhere is written how and where should I create this 'images' directory and put 'background.png' file.
    I do not see any possibility of creating directories in Design mode and drag n dropping or uploading file there.
    So I created 'images' directory into directory where all project files are and put them 'background.png'.
    Now, after I try to run the program, there is error in console that such a file doesnt exist.
    I also tried different path with './' prefix etc but after I hit Run button second time then always no matter what I changed or not changed I see this error:

    Qt Code:
    1. :-1: error: cannot open output file debug\First.exe: Permission denied
    2. collect2.exe:-1: error: error: ld returned 1 exit status
    To copy to clipboard, switch view to plain text mode 

    Weird thing is that when I close whole QT and open it again and hit Run button then first error about "no such a file" appears. After second Run hit I see above one again.

    I tried to Clean and Rebuild the project, different file paths but nothing helps.

    It is my first hit with QT Quick so most probably it is very easy mistake I do but can not see.
    Please help.


    Regards,
    Pablo

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,356
    Thanks
    3
    Thanked 5,010 Times in 4,789 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Blog Entries
    4
    Wiki edits
    10

    Default Re: Source image problem and weird error - How and where add resource files?

    You should put the images directory in the same directory as your qml file in case of running using qmlscene or (as probably in your case) in the current working directory of where the application is executed.

    As for the error -- you have an instance of your application running so Windows is blocking write access to the executable file. Close the application and build the project again.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3

    Default Re: Source image problem and weird error - How and where add resource files?

    Quote Originally Posted by wysota View Post
    You should put the images directory in the same directory as your qml file in case of running using qmlscene or (as probably in your case) in the current working directory of where the application is executed.

    As for the error -- you have an instance of your application running so Windows is blocking write access to the executable file. Close the application and build the project again.
    I used the same directory as my qml file. Crated there exact path that used in code "images/background.png"

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,356
    Thanks
    3
    Thanked 5,010 Times in 4,789 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Blog Entries
    4
    Wiki edits
    10

    Default Re: Source image problem and weird error - How and where add resource files?

    As I said, if you run the program as a regular application (which it seems you do) then the images directory should be placed in the current working directory of where the program is executed. If you are using Creator then it is probably the build directory, which you can check in the project build settings.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5

    Default Re: Source image problem and weird error - How and where add resource files?

    Quote Originally Posted by wysota View Post
    As I said, if you run the program as a regular application (which it seems you do) then the images directory should be placed in the current working directory of where the program is executed. If you are using Creator then it is probably the build directory, which you can check in the project build settings.
    This is so weird. How this http://qmlbook.org/ch01/index.html could be an easy introducing tutorial if such an annoying case is not explained?
    From what I have read, QT Quick should be a quick and easy way to create application so why adding images is hindered in such oldschool way? :| I don't understand it.
    Whould you or anyone else here be so kind to write a step by step explanation what user should do to make this example working?
    Whoever wrote that online-book should provide such instructions not leaving a beginner with nothing..
    Last edited by pabloj; 31st July 2014 at 15:29.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,356
    Thanks
    3
    Thanked 5,010 Times in 4,789 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Blog Entries
    4
    Wiki edits
    10

    Default Re: Source image problem and weird error - How and where add resource files?

    Quote Originally Posted by pabloj View Post
    This is so weird. How this http://qmlbook.org/ch01/index.html could be an easy introducing tutorial if such an annoying case is not explained?
    From what I have read, QT Quick should be a quick and easy way to create application so why adding images is hindered in such oldschool way? :| I don't understand it.
    Whould you or anyone else here be so kind to write a step by step explanation what user should do to make this example working?
    Whoever wrote that online-book should provide such instructions not leaving a beginner with nothing..
    I can't access the book right now so I can't defend what is written there but maybe the tutorial told you to make a "Qt Quick UI" project and instead you created a "Qt Quick Application"?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7

    Default Re: Source image problem and weird error - How and where add resource files?

    Quote Originally Posted by wysota View Post
    I can't access the book right now so I can't defend what is written there but maybe the tutorial told you to make a "Qt Quick UI" project and instead you created a "Qt Quick Application"?
    Using Qt Quick project istead of Qt Quick Application I have this error now:
    QML Image: Invalid image data: file:///D:/QTProjects/untitled/images/background.png

    Ok got it now. Thank you Wysota.

    However there still remains the question what is an easy way to add image files to "Qt Quick Application" project.
    Last edited by pabloj; 31st July 2014 at 16:01.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,356
    Thanks
    3
    Thanked 5,010 Times in 4,789 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Blog Entries
    4
    Wiki edits
    10

    Default Re: Source image problem and weird error - How and where add resource files?

    The easy way is to use Qt Resource System or paths relative to a known path.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9

    Default Re: Source image problem and weird error - How and where add resource files?

    Quote Originally Posted by wysota View Post
    The easy way is to use Qt Resource System or paths relative to a known path.
    Ok so. But QT Quick team really should make it possible to drag and drop resource files into the Design interface like more complicated Eclipse supports it.
    It has to be a synonym of Making Things Easy and Quick.
    But maybe I just overreacted by being used to other framework so far. Will stick to this forum during my learning curve :-)

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,356
    Thanks
    3
    Thanked 5,010 Times in 4,789 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Blog Entries
    4
    Wiki edits
    10

    Default Re: Source image problem and weird error - How and where add resource files?

    Quote Originally Posted by pabloj View Post
    Ok so. But QT Quick team really should make it possible to drag and drop resource files into the Design interface like more complicated Eclipse supports it.
    Where would you like to "drop" them?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #11

    Default Re: Source image problem and weird error - How and where add resource files?

    Quote Originally Posted by wysota View Post
    Where would you like to "drop" them?

    Here: http://s11.postimg.org/bhl8kvggz/here.png

    It would be handy to have possibility of creating resource directories and drag n drop they there.

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,356
    Thanks
    3
    Thanked 5,010 Times in 4,789 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Blog Entries
    4
    Wiki edits
    10

    Default Re: Source image problem and weird error - How and where add resource files?

    Quote Originally Posted by pabloj View Post
    Here: http://s11.postimg.org/bhl8kvggz/here.png

    It would be handy to have possibility of creating resource directories and drag n drop they there.
    And where would these be then located? The design mode is for designing QML documents, not for assembling the project. That's what the edit mode is for and I think you can drop your images to a qrc file there.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  13. #13

    Default Re: Source image problem and weird error - How and where add resource files?

    Quote Originally Posted by wysota View Post
    And where would these be then located? The design mode is for designing QML documents, not for assembling the project. That's what the edit mode is for and I think you can drop your images to a qrc file there.
    New created directors and files put to them would be located in the project directory, standard. Didn't know that I can do so in Edit mode for qrc files, will read about it shortly for sure.

Similar Threads

  1. integrated + binary resource files
    By Le_B in forum Qt Quick
    Replies: 0
    Last Post: 5th June 2011, 16:45
  2. QDir::setCurrent with resource files
    By LarryERamey in forum Qt Programming
    Replies: 3
    Last Post: 20th April 2011, 02:21
  3. Problem in building outside source directory(loading qrc files fails)
    By Jayakrishnan in forum Installation and Deployment
    Replies: 3
    Last Post: 17th October 2009, 16:00
  4. How to compile qt resource files?
    By yangyunzhao in forum Qt Programming
    Replies: 1
    Last Post: 10th August 2009, 06:46
  5. QTextDocument Image resource problem
    By patrik08 in forum Qt Programming
    Replies: 1
    Last Post: 16th August 2007, 15:28

Tags for this Thread

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.