How to change build path on Qt creator - qt

I am struggling to change the build path on Qt creator 4.0.
I've tried everything, but it keeps compiling in a folder in my documents, when my project is actually on my desktop.
Does anyone have a fix ? Thanks

You can either add somthing like this into your .pro file;
DESTDIR = %{sourceDir}/outDir
OBJECTS_DIR = %{sourceDir}/outDir/obj
MOC_DIR = %{sourceDir}/outDir/moc
RCC_DIR = %{sourceDir}/outDir/rcc
UI_DIR = %{sourceDir}/outDir/ui
This should re-direct all the build files into a folder called "outDir" within your source folder (i.e. where your .pro file lives). Note you can use "../" or any absolute path if you really want.
Alternatively you can change the settings in your .pro.user file (which are not part of the config controlled files). To do this you need to edit the build settings in qt creator. You will find an output path that you can change in there. Note you will need to change the path for release and debug builds and also do this for every different build config (e.g. arm-gcc, mingw-gcc, etc...).

Related

How to add library paths in Qt Creator like LIBPATH in Visual Studio?

Question
a) How do we add library paths where the project should look for depended libraries in Qt Creator?
b) How are the settings in project >> Run >> Build Environment related to similar in .pro file? Does the environment variable listed there applies to .pro file as well (well they don't) so what are they exactly?
Context/Details:
Visual Studio has a various environment variables for folders where a project looks for include files, library files or executable files etc. This is rather confusing in Qt Creator and I havne't seen good documentation on it.
The only thing which is obvious is INCLUDEPATHvariable which points to the directories where to look for the include files (.h)
However how do I set the library paths, the path where it should look for dependent libraries/dlls etc? I can specify the exact library with LIBS variable in .pro file, there don't seem to equivalent of LIBPATH variable where it should look for other libraries if not found in current folder.
I have worked around this be adding library path the following way basically using LIBS variable but dropping the library file name and that seems to work and add the path but I don't see this documented anywhere.
LIBS += -L"$$_PRO_FILE_PWD_/Xerces/bin/"
But what makes things more interesting is the settings in Projects >> select 'Run' from current configuration and expand the Run Environment settings.
''
Here there is LIB variable and LIBPATH variable but there are clearly not .pro environment available. It also says here that these settings are local to user and saved in .pro.user file which perhaps suggest it's a different way to set but it doesn't say how to set them in .pro file but it does suggest to set them there if want to apply for all users!
Likewise there are DEPENDPATH AND VPATH and it is not really clearly what they are used for.
I don't have enough Rep to add comments to your question, So am adding my comment in form of answer. I am pretty new to Qt and have been developing Qt GUI application on Linux.
I set this LD_LIBRARY_PATH environment variable with the path to my Qt libraries. Am not sure how much it will be helpful to you since you are using visual studio on windows.
in Projects property go to Build Environment and add a variable with the libs path, example NAME_LIBPATH. So in the .pro file add the following:
# your lib configuration
LIBS += -L$$(NAME_LIBPATH) \
-llibname

Unable to customise the build directory for Qt Creator/qmake

I've got problem trying to specify the build directory (the directory that is to store all the files prior to copying them to the DESTDIR path).
I've got the following values in my .pro file:
DESTDIR = E:/Development/project/build/core/debug
OUT_PWD = E:/Development/project/build/core/debug
OBJECTS_DIR = $$DESTDIR/.obj
MOC_DIR = $$DESTDIR/.moc
RCC_DIR = $$DESTDIR/.qrc
UI_DIR = $$DESTDIR/.ui
Now, all the files eventually end up in that location, however during build, the compiler is always using the "E:/Development/build/MinGW_32bit-Debug/src/core" folder (note the missing project path). This is annoying, because I want to use the /Project/build directory as this location (which is not tracked in my git repo).
Ideally, I'd like this path to be: E:\Development\project\build\src\core\debug.
The reason I want to do this is that the build process has the same location to include the compiled libs from (it's a subdirs project).
I've had a look in the Tools > Options > Build & Run > General settings, and the default build directory is: build/build-%{CurrentProject:Name}-%{CurrentKit:FileSystemName}-%{CurrentBuild:Name}
I've had a look in my project.pro.user file, and found the following line:
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">E:/Development/build/MinGW_32bit-Debug</value>
However I'm unable to change this value. If I edit this line in the file directly, as soon as I open Qt Creator again, the change has reverted back.
Is this a Qt Creator thing, or is it a qmake thing? Would I better off using a different build system such as CMake?
The build directory is "specified" by starting qmake or cmake in the build directory. There's no point to setting it in the .pro file itself.
Qt Creator stores the build directories for a project in the .user file. Any changes made to this file outside of Qt Creator, while the project is open in the Creator, will be lost. Creator loads the file when opening the project, or creates a new one if it doesn't exist.
When the Creator starts the build by invoking qmake or cmake, it starts that process in the build directory. That's also how you should be building the project manually from the command line.
Finally, it makes very little sense to override the destinations of the intermediate build results. They are somewhere within the build directory, and that's all that matters. You're not using these files directly for anything anyway.
The customary way to build a qmake project:
mkdir project-build
cd project-build
qmake ~/project-src
make -j
The build folder should not be within the source tree!
I've recently started keeping them in $TEMP / %TEMP%: manually purging the stale builds of all sort of test projects got old after a while :)

Qt renaming path of the project

sometimes when I rename the path to a qt project, it cannot be run even though I clean qmake and rebuild it!!! the path does not contain any space. and the project is completely correct and I know that the error is for path renaming , for example when I rename :
D:/abd/projects/LAND_2/Land_QT/...
to
D:/abd/projects/LAND_2/Land2_QT_SA/...
it cannot be build and says that some include file is missing(but the file is there!).
what is the problem?
I work with dynamic qt5.2 on windows 7.
Edit:
when I copy the project folder to a new directory( a path upper than current path) then the project can be build and run.
When you rename the path to the project, go to the project folder and delete the file with .pro.user extension. Open the project and Qt will ask you to configure the project. Choose the required kit, build and run the project.It should build successfully now
If you have changed path multiple times the .pro.user file is created multiple times delete all files with this extension and compile

Custom deploy in QTCreator

I am working on QTCreator (3.0.x) targeting an embedded linux device. Everything is fine except the fact that I am not able to add some custom file to deploy step...
In .pro file I set:
target.path = /home/root
INSTALLS += target
and I am able to deploy my executable to the remote device...
Now what if I would like to add some custom files to the deployment process?
I'd tried to add the following lines to my .pro file:
mypackage.files = /path/to/my/files/on/my/pc/*
mypackage.path = /home/root
INSTALLS += mypackage
but it doesn't work...
How can I do that?
I would try to use wildcard/glob in the following way:
$$files(glob) — Returns a list of files which match the specified glob pattern
mypackage.files = $$files(/path/to/my/files/on/my/pc/*)
But in this special case, it would be much easier to just specify the directory since you seem to be grabbing all the files anyhow, so this is what I would write personally:
mypackage.files = /path/to/my/files/on/my/pc

How do I add an entire directory to a QT creator project

I have an existing QT Creator project. I want to add an entire directory to this project. I see that I can right click in the project file browser tree and "Add Existing Files..." However through this dialog box, I can only add individual files. How can I include an entire directory?
The simplest way is to directly edit your .pro file, add HEADERS += mydir/*.h and SOURCES += mydir/*.cpp and the contents of the whole directory will show up in QT Creator. Further reference: http://qt-project.org/doc/qt-5/qmake-project-files.html
Open a terminal, navigate to the folder where you want to have you project file, and then run the command
qmake -project
This will search the current directory and all subdirectories for files with extensions such as .c, .cpp, .h, etc. (the full list is found by typing man qmake).
But keep in mind that it will overwrite your current .pro file if you already have a project set up.
qmake provides a convenient files function for this very purpose. Adding the following line to your project file will add .cpp files inside the src/ directory:
SOURCES += $$files(src/*.cpp)
By default, this is non-recursive. Setting the second parameter to true recursively finds all files:
SOURCES += $$files(src/*.cpp, true)
The files function was introduced since Qt 5.10.
Nowadays you can just right click on project name and select Add existing directory

Resources