I modified my c++ Qt4 project to that all the sources are in an src directory. All the temporary file are stored in a build directory and the target file in a bin directory. Here a snapshot of my .pro file
SOURCES += src/*.cpp
HEADERS += src/*.h
FORMS += gui/myguy.ui
INCLUDEPATH += src/ # Source directory to be included
DESTDIR = bin # Target file directory
OBJECTS_DIR = build # Intermediate object files directory
MOC_DIR = build # Intermediate moc files directory
my problem is the following. When I build the application qt automatically transforms ui_mygui.h. This is by default stored on the root of the project. How can I specify the location where I want this file to be put?
Thanks
Use the UI_DIR variable. This is where those files will be generated.
Related
How to add all files in some sub-directory in qt project file.
for example, my source tree is:
src
app/
foo/
ui/
common/
Now I add all files like this
SOURCES += ./*.cpp \
./app/*.cpp \
./app/foo/*.cpp \
./ui/*.cpp \
./common/*.cpp
Is there any way to add all these files under src directory to SOURCES?
You have to use the files function:
SOURCES += $$files("*.cpp", true)
In my .pro file in Qt project, I have used these two lines for adding necessary LIBS.
LIBS += -L "../../lib/bin/libname.a"
LIBS += -L "../../rfm2g/winver/libname.lib"
error: ../../rfm2g/winver/libname.lib: No such file or directory
The compiler found the file libname.a, but could not find the libname.lib, although the relative path for both files is correct. Does anybody have an idea?
The -L option wants a directory for -l to search, not the path to the actual library.
So you should either write e.g.
LIBS += -L../../lib/bin -lname
LIBS += -L../../rfm2g/winver -lothername
Or link with them directly
LIBS += ../../lib/libname.a
LIBS += ../../rfm2g/winver/libname.lib
Also make sure that the paths actually are correct. If you change to the build directory, and try to list the files (using ls or dir depending on platform) using the paths you have, can you list both files?
I'm using Qt Creator 2.7.0 on ubuntu 13.04.
I've just recently ran into the idea of using libraries, and they're a whole new thing for me.
I've just figured that I need to have the following in my application's .pro file to use a library of my own:
LIBS += -L<lib's dir> -l<lib's name>
INCLUDEPATH += <headers' dir>
// for example:
LIBS += -L$$PWD/../MyLib/release/ -lMyLib
INCLUDEPATH += $$PWD/../MyLib/src/
As you see, I have all my projects in a folder called Programming (the .. in this case)
Each of my project have .pro and .pro.user files in the root, source files in a sub folder /src and the release in an other sub folder /release.
So, this is what my Programming folder looks like:
Programming
MyLib
MyLib.pro
MyLib.pro.user
src
myclass.h
myclass.cpp
release
libMyLib.a
Makefile
myclass.o
MyApp
MyApp.pro
MyApp.pro.user
src
main.cpp
release
main.o
Makefile
MyApp
However, I figured that I could create a folder Programming/libs/, and add libMyLib.a and myclass.h files inside that libs folder.
I would do the same for all of my libraries, and then I could always include them like this:
LIBS += -L$$PWD/../lib/ -lMyLib
INCLUDEPATH += $$PWD/../lib/
The problem is, I'd get include path for every library stored on my computer and the libs folder would become a mess, especially if there are two headers with same name on different libraries.
I'm really new to using libraries, is there a general solution on how they should be located on your computer, and how to include them into your projects?
You could mimic libraries like Boost and have a directory tree like this:
MyLib
build
Makefile, .pro or .sln file here
lib
MyLib
// your .so / .a here
include
MyLib
// your .h here
src
// your .cpp here
CMake or qmake file here
This way you have an out-of-source build tree (in build/) so that your binary files are not mixed up with your source files.
The lib/ and include/ directories are handy because you can then define an install build target. If you then type
make install
it will copy everything to usr/local/lib and user/local/include so that your App can simply do #include <MyLib/some_header.h> and you can link directly against your library binaries (because you copied everything to a location in your system wide path). There is also no danger of name clashes because you wrapped it inside your own MyLib subdirectory.
I have a program that draws the Earth and it uses the following code to read the texture file:
Images::RGBImage surfaceImage;
surfaceImage=Images::readImageFile("",Vrui::openFile("/home/rodrtu/Desktop/SolarSystem/land_shallow_topo_2048.png"));`
The way I have it set up it only works on my desktop, but I want other people to have access to my program files and pictures, and be able to get the program working on their computer. What should I use instead of using "/home/rodrtu/Desktop/SolarSystem/land_shallow_topo_2048.png"
If I add a folder to the same place as my .cpp file, should I make changes to my makefile?
Here is my makefile
VRUI_MAKEDIR := /opt/local/Vrui-2.6/share/make
ifdef DEBUG
VRUI_MAKEDIR := $(VRUI_MAKEDIR)/debug
endif
INSTALLDIR := $(shell pwd)
# Set resource directory: I added this images folder to the same place as my
# .cpp file, but it still doesn't work
RESOURCEDIR = images
########################################################################
########################################################################
# Include definitions for the system environment and system-provided
# packages
include $(VRUI_MAKEDIR)/SystemDefinitions
include $(VRUI_MAKEDIR)/Packages.System
include $(VRUI_MAKEDIR)/Configuration.Vrui
include $(VRUI_MAKEDIR)/Packages.Vrui
# Set installation directory structure:
BININSTALLDIR = $(INSTALLDIR)/$(EXEDIR)
RESOURCEINSTALLDIR = $(INSTALLDIR)/$(RESOURCEDIR)
########################################################################
########################################################################
PACKAGES = MYVRUI
########################################################################
########################################################################
ALL = $(EXEDIR)/NewPlanet
.PHONY: all
all: $(ALL)
########################################################################
#'make clean'
########################################################################
.PHONY: extraclean
extraclean:
.PHONY: extrasqueakyclean
extrasqueakyclean:
# Include basic makefile
include $(VRUI_MAKEDIR)/BasicMakefile
########################################################################
########################################################################
$(EXEDIR)/NewPlanet: $(OBJDIR)/NewPlanet.o $(OBJDIR)/drawShape.o
You should use relative path like Beta suggested. Put a "data" folder on the same folder than your executable and use :
Vrui::openFile("./data/land_shallow_topo_2048.png")
File opening should be relative to the program directory, so you could create a sub directory inside your source dir for pictures. Make sure to let the user know where to place these pictures however,
g-dev#g$ mkdir dat
g-dev#g$ mv pic.jpg dat/pic.jpg
then in source:
::readImageFile("", Vrui::openFile("pic.jpg")
adding the directory in CMake:
include_directories ("${PROJECT_SOURCE_DIR/dat}")
adding the directory in VS:
here
(make sure you're using provided MSVS macros for your file path $(ProjectDir) or $(SolutionDir) )
I have qt project proj1 which depends on another (proj2).
Directory tree is like this:
common/
`--/pr1/
proj1.pri
main.cpp
`--/pr2/
proj2.pri
src1.cpp
src2.cpp
proj1 includes proj2:
include(../proj2.pri)
while in proj2.pri sources are listed as they are in current (pr2) dir:
SOURCES += src1.cpp \
src2.cpp
So when I try to build proj1 I'm getting such error:
make: *** No rule to make target `src1.cpp', needed by `src1.o'. Stop.
Is there any correct way to include subproject's sources (I need to do so for debugging) with help of pri-files ?
In proj1.pri, before including proj2.pri:
PROJECT_ONE_IS_DEFINED = 1
In proj2.pri:
isEmpty(PROJECT_ONE_IS_DEFINED){
DEPENDPATH += pr2
INCLUDEPATH += pr2
} !isEmpty(PROJECT_ONE_IS_DEFINED){
DEPENDPATH += ..\pr2
INCLUDEPATH += ..\pr2
}
This way project 2 will be included normally if used by itself, and will be included properly if used as part of project 1....
Or, you can simply add path to pr2 to DEPENDPATH in project1, as long as path to your cpp files is added to dependpath, make will work fine
EDIT:
The most efficient way that allows to include .pri file in many projects without worrying about specific path for each case is to add
DEPENDPATH += $$PWD
INCLUDEPATH += $$PWD
in the beginning of each .pri file.