Results 1 to 15 of 15

Thread: Problem to find file path

  1. #1
    Join Date
    Oct 2007
    Posts
    201
    Thanks
    19
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Problem to find file path

    Hi all.
    I'm creating a solution by using Cmake. here I've 2 directory, one is (source directory), where i ve sored my files and another is (Target Dir) where solution is getting created. if I'm trying to get the file path by using
    QDir::currentPath(); its giving the targetdirectory path.(e.g D:/TargetDir/mymodule/src). But i need the source file path (e.g D:/sourceDir/mymodule/src).
    But I didn't find any thing in net or assistant.
    Any help ll be appriciated.

    Thank You.
    Cheers,
    Phillip



    --- Please post the solution you got to solve your problem. It may help others.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problem to find file path

    I'm sure there is no way of getting path to the source directory during runtime if that is what you are asking about.

  3. #3
    Join Date
    Oct 2007
    Posts
    201
    Thanks
    19
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem to find file path

    Quote Originally Posted by wysota View Post
    I'm sure there is no way of getting path to the source directory during runtime if that is what you are asking about.
    I think at leaset there shd b some thing thing to find DIrectory? Can u plz tell me.
    Cheers,
    Phillip



    --- Please post the solution you got to solve your problem. It may help others.

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Problem to find file path

    Why do you expect the source directory to be there? What if the program is run on another machine which doesn't even have it?
    J-P Nurmi

  5. #5
    Join Date
    Oct 2007
    Posts
    201
    Thanks
    19
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem to find file path

    Quote Originally Posted by jpn View Post
    Why do you expect the source directory to be there? What if the program is run on another machine which doesn't even have it?
    Actually inside source directory, 3 .qss files are there. I need the path to include. it.
    Thats why i need it.
    Cheers,
    Phillip



    --- Please post the solution you got to solve your problem. It may help others.

  6. #6
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    554
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem to find file path

    Your idea is wrong. You can't know where somethins is on another computer and therefore can't hardcode your source path into your app. You have to put your files into a well-known location and load it from there.

  7. The following user says thank you to ChristianEhrlicher for this useful post:

    phillip_Qt (19th March 2008)

  8. #7
    Join Date
    Oct 2007
    Posts
    201
    Thanks
    19
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem to find file path

    Quote Originally Posted by ChristianEhrlicher View Post
    Your idea is wrong. You can't know where somethins is on another computer and therefore can't hardcode your source path into your app. You have to put your files into a well-known location and load it from there.
    I ve a directory named as ColorS. inside that a sub directori is there named as resources. I need the path of that resources. How to get it?
    Cheers,
    Phillip



    --- Please post the solution you got to solve your problem. It may help others.

  9. #8
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    554
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem to find file path


  10. #9
    Join Date
    Oct 2007
    Posts
    201
    Thanks
    19
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem to find file path

    Quote Originally Posted by ChristianEhrlicher View Post
    This one giving the path where dll file is getting created. But i wanna the file path. Lets assume it is("D:\PRGM\Colors\Resources"). How to get this.?
    Cheers,
    Phillip



    --- Please post the solution you got to solve your problem. It may help others.

  11. #10
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    554
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem to find file path

    applicationDirPath() returns the path where the executable currently is.

  12. #11
    Join Date
    Oct 2007
    Posts
    201
    Thanks
    19
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem to find file path

    Quote Originally Posted by ChristianEhrlicher View Post
    applicationDirPath() returns the path where the executable currently is.
    Ya ChristianEhrlicher, You are absolutly right. Im also geeting this. But as i posted i need the path like("D\PRGM\Colors\Resources"). My solution is getting created in ("D\Target\bin\debug\here is my exe") as i m making solution by using cmake file.
    Cheers,
    Phillip



    --- Please post the solution you got to solve your problem. It may help others.

  13. #12
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    554
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem to find file path

    As I said earlier - you need to start from a well known point. The only path you know exactly is the one from your executable. It doesn't matter what buildsystem you use. The only important thing is where your paths are once the app is installed on the target computer(s).

  14. #13
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem to find file path

    I would suggest make the path of resources relative to the application path.
    and use it in .pro file to include directories.

    Or use some file to store the path and read from there.

    Both solutions will help u to load resources and easily modify the path even if u install the application on some other computer

  15. #14
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problem to find file path

    Be aware that the path where you build the application is not its final resting place. After building your should install the application to a defined path along all the resources. Especially that installing the application might require super user privileges.

  16. #15
    Join Date
    Oct 2007
    Posts
    201
    Thanks
    19
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem to find file path

    Than you all. I solved it. the code worked for me is

    Myfunction(QString qssfilename)
    {
    QFile file(":/"+qssfilename+".qss");
    }
    Last edited by phillip_Qt; 28th April 2008 at 10:12. Reason: correct code
    Cheers,
    Phillip



    --- Please post the solution you got to solve your problem. It may help others.

Similar Threads

  1. QT string Find problem
    By kingslee in forum Qt Programming
    Replies: 2
    Last Post: 16th October 2006, 20:45
  2. problem with linking
    By mickey in forum Qt Programming
    Replies: 49
    Last Post: 12th August 2006, 21:41
  3. Replies: 7
    Last Post: 1st August 2006, 21:15
  4. Problem with reading a file
    By Buhmann in forum Qt Programming
    Replies: 11
    Last Post: 17th February 2006, 13:02
  5. QProcess problem with windows batch file
    By bood in forum Qt Programming
    Replies: 11
    Last Post: 6th January 2006, 08:08

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.