Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I wish to use QImage in Qt to load and save images. While I can load an image, for whatever reason it wont let me save the image.
So I started writing a simple code, made a simple png test file using paint, put it into the same folder as the project itself.
#include <QImage>
#include <iostream>
int main(){
QImage image;
image.load("test.png");
if (image.isNull()){
std::cout << "ERROR!\n";
else{
std::cout << "IMAGE LOADED!\n";
image.save("test1.png");
return 0;
During running the program I get the message of "IMAGE LOADED!" from the application output, however when I check the folder I expect the same image saved as test1.png, which doesn't appear at all.
So, how do I actually save an image? What did I miss?
–
–
–
–
–
In the other comments mentioned the image got saved into the working directory, which is not the same as the folder where the project is located.
In my specific case I got the image by adding a full path to the project like
int i = image.save("C:\\Users\\UserName\\Documents\\QT\\testing_ground_cpp\\" + string);
to find the image.
Ideally I should directly access with the working directory.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.