August 22, 2011

MFreeM MFreeM
Lab Rat
5 posts

QPixmap .png in the same project directory


Hi there,

I want to create a Qpixmap object with a .png that is in a subfolder within the same project directory without typing in the entire path.I think there is a way to do this. But for the life of me i cant remember.

so instead of typing

  1. QPixmap* pixmap = new QPixmap("c:\\documents and settings\\....\\projects\\program01\\cards\\1.png");

just type
  1. QPixmap* pixmap = new QPixmap("cards\\1.png") or something?

Any idea?


3 replies

August 22, 2011

cincirin cincirin
Lab Rat
473 posts

Why you do not use The Qt Resource System [] ?

August 22, 2011

octal octal
Lab Rat
73 posts

You can access the path of your application by calling applicationDirPath []

If you want the native separator of folders on your system, you have QDir::separator []

By the way, do you really need a pointer to your QPixmap ?

Otherwise, you still can use the Qt Resource System, as stated above :)

August 22, 2011

Rahul Das Rahul Das
Ant Farmer
439 posts

  1. QPixmap* pixmap = new QPixmap("some.png");

This is should work. Since you are not using the resource system, you must do one thing :) . Copy the image to build directory.

According to doc []

If fileName contains a relative path (e.g. the filename only) the relevant file must be found relative to the runtime working directory.



    Rahul Das


  ‹‹ [SOLVED] Editable QComboBox get manually inserted value      ItemHasNoContents and boundingRect ››

You must log in to post a reply. Not a member yet? Register here!