Look at these two documents:

http://doc.trolltech.com/4.1/qt-conf.html
http://doc.trolltech.com/4.1/qlibraryinfo.html#location

By creating a qt.conf in your build directory next to your application
you can make your code completely agnostic to the location of your data
files.


HTH

Michael

On 01/26/2011 05:25 PM, Benjamin Kurz wrote:
> ok, sorry, let's make it more real. I cannot disclose much code, but
> it's like this:
> 
> I have a normal Qt application started out of a main.cpp which is
> located in $SOURCE_DIR/src
> In another QWidget also located in $SOURCE_DIR/src I call a function
> which is also declared in $SOURCE_DIR/src
> with something like this:
> loadfile("./data/file1");
> 
> if I build the application in-source it works fine.
> if I build it in a different place, let's say $BUILD_DIR, it does not
> work anymore.
> 
> The executables in both cases are on the top level of $SOURCE_DIR
> (in-source build) or at the top level of $BUILD_DIR (out-of-source build).
> 
> I copy the files with cmake with the following:
> file(COPY ${PROJECT_SOURCE_DIR}/data DESTINATION ./)
> this works fine, the files are copied and are in the same hierarchy as
> in the source tree.
> 
> Maybe it's not even a full cmake question, if so I am sorry for that.
> But somehow I have to tell my code where to find a file when I have an
> out-of-source build.
> 
> Hope that clearified it a bit, and did not make it less understandable. :)
> 
> Thanks so far.
> 
> Benjamin
> 
> Am 26.01.2011 16:12, schrieb David Cole:
>> Send some code for us to look at.
>>
>> If the cwd is where your exe is, and there's a file at "./data/file1"
>> then you should certainly be able to open and read that file with that
>> file name.
>>
>> Maybe your cwd is not what you think it is.
>> Maybe your code changes it somewhere between launching and attempting
>> to open the file.
>>
>> I don't understand where you're using a
>> filepath = "./data/file1"
>> reference? In your source code? In a settings file of some sort?
>> Certainly not in a CMakeLists.txt file since this is not cmake
>> syntax...
>>
>>
>> ??
>>
>> David
>>
>>
>> On Wed, Jan 26, 2011 at 9:54 AM, Benjamin Kurz
>> <benjamin.k...@bioskill.com> wrote:
>>   
>>> Hello everyone,
>>>
>>> Currently I'm using cmake for building my c++/Qt project.
>>> The source directory structure looks like this:
>>> Project
>>> |_ src
>>> |_ include
>>> |_ data
>>>
>>>
>>> Currently I run cmake from the source directory, having an in-source-build.
>>> Now I want to be able to have a complete seperate build folder.
>>> It compiles fine and it runs ok, unless I need access to a file in the
>>> data folder.
>>> Currently I access files like this: filepath = "./data/file1"
>>> But data is of course not available in the build directory.
>>> So I copied the files during the cmake process, which also works fine.
>>>
>>> But when I run the program I get an exception because the file is not found.
>>> I tried a lot of possibilities:
>>> filepath = "../data/file1"
>>> filepath = "data/file1"
>>> filepath = "file1"
>>>
>>> but nothing seems to work.
>>>
>>> The executable is on the top directory in the build directory.
>>> The filepath is defined and used in a class in ./src directory.
>>>
>>> I am not sure how to fix this or which path to use?!
>>>
>>> Any advice is appreciated.
>>>
>>> Thanks
>>>
>>> Benjamin

_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Reply via email to