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:
Code:
import QtQuick 2.0
Image {
id: root
source: "images/background.png"
}
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:
Code:
:-1: error: cannot open output file debug\First.exe: Permission denied
collect2.exe:-1: error: error: ld returned 1 exit status
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
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.
Re: Source image problem and weird error - How and where add resource files?
Quote:
Originally Posted by
wysota
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"
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.
Re: Source image problem and weird error - How and where add resource files?
Quote:
Originally Posted by
wysota
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..
Re: Source image problem and weird error - How and where add resource files?
Quote:
Originally Posted by
pabloj
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"?
Re: Source image problem and weird error - How and where add resource files?
Quote:
Originally Posted by
wysota
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:
Quote:
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.
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.
Re: Source image problem and weird error - How and where add resource files?
Quote:
Originally Posted by
wysota
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 :-)
Re: Source image problem and weird error - How and where add resource files?
Quote:
Originally Posted by
pabloj
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? :)
Re: Source image problem and weird error - How and where add resource files?
Quote:
Originally Posted by
wysota
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.
Re: Source image problem and weird error - How and where add resource files?
Quote:
Originally Posted by
pabloj
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.
Re: Source image problem and weird error - How and where add resource files?
Quote:
Originally Posted by
wysota
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.