Results 1 to 4 of 4

Thread: relative file name

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2010
    Posts
    12
    Qt products
    Qt4 PyQt3 PyQt4
    Platforms
    Unix/X11

    Default relative file name

    hi all could do with some help

    I can't get this to work

    Qt Code:
    1. self.setWindowIcon(QIcon("file.jpg"))
    To copy to clipboard, switch view to plain text mode 

    if i write it with a full path it works, but with a relative path like this it won't.

    am i doing something wrong or does QT not except relative file name?

    thanks for any help

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: relative file name

    Or perhaps it simply can't find the file?

    Instead of launching from Qt Creator, launch the exe yourself with the file.jpg in the same directory.

  3. #3
    Join Date
    Feb 2010
    Posts
    12
    Qt products
    Qt4 PyQt3 PyQt4
    Platforms
    Unix/X11

    Default Re: relative file name

    Hi thanks for the reply

    Yes I tried opening the exe with the jpg in the same fire and no go.

    I should say here that the the system that i am using is a linux system, and i now think this might be the problem.

    I ran some tests, and found that if I place the image file in my home directory it works no matter where i place the exe file. It seem the my system is looking for any file that has no full path from the home directory. I tested this further by removing the image file from the home directory and then adding just the subdirectory to a file name and all works great.

    I tried my program on a windows system and it works ok so I guess thats what is going on

    It seem this maybe a Linux problem rather than QT has anyone else see this with linux...?
    Last edited by benlyboy; 27th June 2010 at 14:43.

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: relative file name

    The relative path is not relative to the location of the executable. Qt will be looking in the current working directory of the application process for the file. By default the application gains the current working directory of the process that launched it. If you launch it manually from your home directory then that is where it looks for the file. If Qt Creator launches the application then the current working directory may be different.

    If you want to find the location of the executable to build a path to your file then use QCoreApplication::applicationDirPath().

Similar Threads

  1. Relative paths in Qt
    By drmath in forum Qt Programming
    Replies: 2
    Last Post: 30th June 2010, 16:50
  2. relative position
    By franco.amato in forum Newbie
    Replies: 2
    Last Post: 8th December 2009, 18:08
  3. Replies: 7
    Last Post: 2nd November 2009, 19:07
  4. Rubberband relative to QGraphicsScene
    By pherthyl in forum Qt Programming
    Replies: 25
    Last Post: 20th December 2007, 19:30
  5. QScrollArea relative viewport coordinates
    By kalanikta in forum Qt Programming
    Replies: 1
    Last Post: 21st April 2006, 10:30

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.