PDA

View Full Version : Problem to find file path



phillip_Qt
19th March 2008, 06:47
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.

wysota
19th March 2008, 06:50
I'm sure there is no way of getting path to the source directory during runtime if that is what you are asking about.

phillip_Qt
19th March 2008, 07:06
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.

jpn
19th March 2008, 07:32
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?

phillip_Qt
19th March 2008, 07:42
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.

ChristianEhrlicher
19th March 2008, 07:52
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.

phillip_Qt
28th April 2008, 05:58
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?

ChristianEhrlicher
28th April 2008, 06:42
Use QCoreApplication::applicationDirPath () (http://doc.trolltech.com/4.3/qcoreapplication.html#applicationDirPath)

phillip_Qt
28th April 2008, 06:56
Use QCoreApplication::applicationDirPath () (http://doc.trolltech.com/4.3/qcoreapplication.html#applicationDirPath)

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.?

ChristianEhrlicher
28th April 2008, 06:59
applicationDirPath() returns the path where the executable currently is.

phillip_Qt
28th April 2008, 07:22
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.

ChristianEhrlicher
28th April 2008, 07:25
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).

aamer4yu
28th April 2008, 07:31
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

wysota
28th April 2008, 07:44
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.

phillip_Qt
28th April 2008, 10:06
Than you all. I solved it.:) the code worked for me is

Myfunction(QString qssfilename)
{
QFile file(":/"+qssfilename+".qss");
}