Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QImage class : file loading

Tags:

qt

If I want to load file directly (QImage i1("image1.jpg");) where should I store it?

If I have to give full path of file or only short path is required?

like image 783
Sanjay Bhosale Avatar asked May 05 '26 06:05

Sanjay Bhosale


2 Answers

If you don't want to worry about an image (and you are not having too much of them), consider using Qt Resources. Qt Resources will embed the image into the executable independent of the platform. The images would be pulled from the filesystem at compile time, and an IDE like Qt Creator actually helps you with that.

E.g. if you created an resource called "image" containing your file, you could reference your image by typing

QImage(":/images/image1.jpg")

like image 83
danimo Avatar answered May 07 '26 10:05

danimo


If you want to use QImage as you have written in your question, then your image needs to be in your current directory. Most likely that will be the directory where your executable is stored.

Otherwise you will have to give either a relative or full path.

like image 28
Bart Avatar answered May 07 '26 12:05

Bart



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!