August 22, 2011

MFreeM MFreeM
Lab Rat
12 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?

THANKS!

3 replies

August 22, 2011

cincirin cincirin
Ant Farmer
453 posts

Why you do not use The Qt Resource System [doc.qt.nokia.com] ?

August 22, 2011

octal octal
Lab Rat
74 posts

You can access the path of your application by calling applicationDirPath [doc.qt.nokia.com]

If you want the native separator of folders on your system, you have QDir::separator [doc.qt.nokia.com]

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
Robot Herder
430 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 [doc.qt.nokia.com]

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

 Signature 

——————————-

    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!