Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QPixmap .png in the same project directory
QtWS25 Last Chance

QPixmap .png in the same project directory

Scheduled Pinned Locked Moved General and Desktop
4 Posts 4 Posters 7.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MFreeM
    wrote on last edited by
    #1

    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
    @
    QPixmap* pixmap = new QPixmap("c:\documents and settings\....\projects\program01\cards\1.png");
    @
    just type
    @
    QPixmap* pixmap = new QPixmap("cards\1.png") or something?
    @

    Any idea?

    THANKS!

    1 Reply Last reply
    0
    • C Offline
      C Offline
      cincirin
      wrote on last edited by
      #2

      Why you do not use "The Qt Resource System":http://doc.qt.nokia.com/latest/resources.html ?

      1 Reply Last reply
      0
      • O Offline
        O Offline
        octal
        wrote on last edited by
        #3

        You can access the path of your application by calling "applicationDirPath":http://doc.qt.nokia.com/latest/qcoreapplication.html#applicationDirPath

        If you want the native separator of folders on your system, you have "QDir::separator":http://doc.qt.nokia.com/latest/qdir.html#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 :)

        1 Reply Last reply
        0
        • R Offline
          R Offline
          Rahul Das
          wrote on last edited by
          #4

          @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":http://doc.qt.nokia.com/latest/qpixmap.html#QPixmap-4

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


          Declaration of (Platform) independence.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved