Include a qmake project in another qmake project - c++

I have created an application in qt/c++
Browser/Browser.pro
To start the browser, I need an agent. I have created an agent and store it in the Browser folder
Browser/Browser.pro
Browser.cpp
main.cpp
Agent/Agent.pro
Agent/agent.cpp
When building the Browser, I'm generating an app but it's only build the browser.
I have added in Browser.pro the line below:
SUBDIRS += \
Agent/Agent.pro
browser.depend = Agent/Agent.pro
My concerns is that I'm trying to build browser.app and automatically agent.app .
The goal after is to integrate the the agent.app generated in the resource of the browser.app
Any idea

SUBDIRS variable is only interpreted in TEMPLATE=subdirs pro file.
Also, it does take only the directory name where to find your project, not the .pro itself.
You should create a directory for your Browser project and get this:
Browser/
|-Browser.pro
|-Browser/
|-Browser.pro
|- ...
|-Agent/
|-Agent.pro
|- ...
And then your main project file will be like this:
Browser.pro:
TEMPLATE = subdirs
SUBDIRS = Agent Browser
CONFIG += ordered
More information about subdirs : http://doc.qt.io/qt-5/qmake-variable-reference.html#subdirs

Related

UI_project.h not found for QT project

I made a QT GUI project in VS 2019. It ran perfectly through VS. Copied the entire project files directory to Linux partition. Ran qmake -project in the directory containing the 'test2.sln' file to create a 'test2.pro' file. Opened the '*.pro' file through QT Creator. It imported everything fine. But, when building it it errors out saying "ui_test2.h file not found".
The test2.pro contains:
TEMPLATE = app
TARGET = test2
INCLUDEPATH += .
DEFINES += QT_DEPRECATED_WARNINGS
HEADERS += test2/test2.h test2/x64/Release/uic/ui_test2.h
FORMS += test2/test2.ui
SOURCES += test2/main.cpp test2/test2.cpp test2/x64/Release/rcc/qrc_test2.cpp
RESOURCES += test2/test2.qrc
What should I do to fix this?
1) remove folder with build (rm -r nameOfFolder)
2) rename your UI file (test2.ui -> mainwindow.ui) for example
3) check out name of own class and name of qt class in UI file (you can open it via vim or nano)
After that try to rebuild your project!
I hope you'll have done this with good results!

dyld: Library not loaded: myOwnLibrary

Context
I'm developing an app in Qt with Qt Creator in OS X. Right now my file organization is a mess (every file is the same folder) so I've decided to move to another project structure that also allows me to also run unit tests.
What have I tried
Following this blog entry I tried to create the same project (just for testing purposes).
Problem
Everything compiles but when executing it gives an error Library not loaded.
I thought that maybe I was doing something wrong so I cloned the example repo and try it again with a working example. But it gives me the same error:
dyld: Library not loaded: libmyapp.1.dylib
Referenced from: /Users/(my build folder)/app/app
Reason: image not found
The example is supposed to be right. The only changed I made is to remove the test subdir as I haven't installed yet UnitTest++ so my .pro file is like this:
TEMPLATE = subdirs
CONFIG+=ordered
SUBDIRS = \
src \
app
app.depends = src
OTHER_FILES += \
defaults.pri
Am I doing something wrong? Is there any step that I forgot?
Edit 1:
Creating manually a Frameworks folder and adding the libmyapp.1.dylib inside the bundle makes the app work. But I think this step should be done automatically
Edit 2:
I've tried to run macdeployqt as suggested. It seems that the app is trying to get the library from the system path instead of the provided:
macdeployqt app.app
ERROR: no file at "/usr/lib/libmyapp.1.dylib"
I have done the following to get the correct dependencies on a lib in the executable...
This code in the application pro file sets dependencies and also places the files directly into the Contents/Framework folder inside bundle (I chose to make the executable do all the work)
# to get the dependencies
INCLUDEPATH += ../libmyapp
macx {
LIBS += ../libmyapp/libmyapp.1.dylib
PRE_TARGETDEPS += ../libmyapp/libmyapp.1.dylib
MY.path = Contents/Frameworks
MY.files = ../libmyapp/libmyapp.1.dylib
QMAKE_BUNDLE_DATA += MY
}
Alternatively you can make your lib become a framework .. 2 options in this post:
How to create a Bundle Library (mh_bundle) with qmake on Mac OS X?
Would be good to read on the process of deploying an app on OS X... The tool trojanfoe was thinking of, for deploying qt apps, is called macdeployqt
Working with bundles of C++ programs with dependencies on Mac OS X can be a real pain. A workaround until you actually need to ship your app as a bundle is tell Qt not to create a bundle at all. Add the following to your app.pro file:
CONFIG -= app_bundle
Then you may add the dylib to the output directory yourself and it should hopefully work fine.
Another option is to set/add the environment variable LD_LIBRARY_PATH in the Run settings for your project in Qt Creator to point to the path where your compiled dylib is located.
I'm not sure that the above works, but those are my best guesses from earlier experience with similar issues. Also, make sure you are using the newest versions of Qt and Qt Creator.

QT multiple project configuration

New to QT but can't see how I can't switch between debug and release configurations across multiple projects.
I have a session with 20+ projects in it, and switching between 4 configurations means going into each one and selecting a different config, which is just a different flag passed to the makefile. This is far too time consuming, is there a quicker way?
You can make a Subdirs project and add your subprojects to its .pro file :
TEMPLATE = subdirs
CONFIG += ordered
SUBDIRS += \
project1 \
project2 \
project3 \
...
Here the project directories should be added in the Subdirs project directory alongside its .pro file. Notice that the name of the .pro file of the subprojects should be the same as it's folder name. This way the subprojects are detected and listed in the Projects pane automatically.
You can create a new project like foobar.pro:
TARGET = foobar
TEMPLATE = subdirs
SUBDIRS += ../foo \
../bar
This will enable you to compile foo.pro and bar.pro on release/debug mode with one command.

qt build output directory being totally ignored

i've been using qt recently and was organizing some projects into a Subdirs to begin a larger project, and went to manipulate the pro files so as to place my build files where i want them. However, the changes i make to any of them are being ignored. I have a main project that compiles to an executable, and then two other projects that compile to DLL's. I would like for the executables and libraries to end up in the same directory, where the subdirs pro file is located. Here is the pro file for my subdirs that i've tried:
TEMPLATE = subdirs
SUBDIRS += \
MainWindow \
FileLoader
Debug:DESTDIR = $$_PRO_FILE_/debug
Debug:OBJECTS_DIR = $${DESTDIR}/.obj
Debug:MOC_DIR = $${DESTDIR}/.moc
Debug:RCC_DIR = $${DESTDIR}/.rcc
Debug:UI_DIR = $${DESTDIR}/.ui
Release:DESTDIR = $$_PRO_FILE_/release
Release:OBJECTS_DIR = $${DESTDIR}/.obj
Release:MOC_DIR = $${DESTDIR}/.moc
Release:RCC_DIR = $${DESTDIR}/.rcc
Release:UI_DIR = $${DESTDIR}/.ui
After that, i put that same path block in all three of the subprojects pro files, and still all the build files end up in a directory in my Qt Projects directory called "build-Chromatic-Desktop_Qt_5_1_1_MSVC2010_32bit-Debug" (Chromatic is the name of the project). Can someone help me wrangle my pro files to do make this stuff where i want it? Again, i want all the build files for all projects in the directory where the subdirs pro file is.
Instead of using _PRO_FILE_ you should use _PRO_FILE_PWD_ because the first variable contains the path to the project file in use and the second contains the path to the directory containing the project file in use.
In Qt Creator you should deselect the Shadow build checkbox: "By default, Qt Creator builds projects in a separate directory from the source directory, as shadow builds. This keeps the files generated for each build and run kit separate. If you only build and run with a single kit, you can deselect the Shadow build checkbox."

Installing files using qmake: how to get the executable too?

I'm building my app with qmake.
my project.pro file looks something like:
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += [all source files]
HEADERS += [all headers]
After a build, I want "make install" to copy everything required in a subfolder, so I added the following:
package.path = $${OUT_PWD}/package
package.files += myapp.exe myapp.ini [other dlls]
package.CONFIG = no_check_exist
INSTALLS += package
I cannot have in any way my compiled binary to be copied alongside; I prefixed it with $$OBJECTS_DIR/ and others, but I can't find the right variable containing the path to the build directory!
It seems these variables are meant as a way to change qmake's behaviour, for example to change the build directory. I don't want to change it; I want to access it!
Is there any other variable I could use? Basically, I want to put in "package.files" the full path to the compiled executable binary.
Thanks!
qmake puts the complied executable (or library) in the location pointed to by DESTDIR.
Usually, when I want to put the binary and support files, I will set DESTDIR to the location I want to install stuff, then set any INSTALLS.path to DESTDIR.
DESTDIR = $${OUT_PWD}/package
package.path = $${DESTDIR}
package.files += myapp.exe myapp.ini [other dlls]
package.CONFIG = no_check_exist
INSTALLS += package