Standalone Application Qt - c++

I have a Qt application that needs a specific folder and some files. This folder is now located inside the project folder. Is there any way to make this folder be "generated" when I use the make command to create the Standalone version of the program.
I was thinking about changing something in my .pro file but could not figure out any solution that way.
The folder contains some .lua code that I need to make the software work properly if the user select some functionalities.

One solution that copy these resources to destination folder the binary installed via qmake. Please refer to the link enter link description here
Some answers are out-of-date but inspire enough.

Possible solution(see http://doc.qt.io/qt-5/qmake-advanced-usage.html):
TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += .
# Input
SOURCES += main.cpp
lua_dir.target = .makedir
lua_dir.commands = test -d lua_dir || mkdir lua_dir
QMAKE_EXTRA_TARGETS += lua_dir
PRE_TARGETDEPS += .makedir
You should replace lua_dir.commands = test -d lua_dir || mkdir lua_dir with appropriate to you command, I use bash command intepreter here.

you can change DESTDIR qmake variable to compile binary file straight to specified directory.
you can use INSTALLS:
someTarget.path = $$OUT_PWD/MyFolder
someTarget.files = $$PWD/SomeDirToCopy/*
INSTALLS += someTarget
this will copy all files from ProjectDirectory/SomeDirToCopy folder to BuildDirecory/MyFolder after you run make install in build directory.

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!

Qt install won't copy files

I'm using Qt 5.5 for a project, and am trying to use the install feature to copy files into the build directory. I have in my .pro (this is a simplified version I am using to try and figure out the issue):
copy_files.path = $${OUT_PWD}/debug
copy_files.files = win32_libs/*
INSTALLS += copy_files
I have in the build configuration an extra step after "make" which is "Make install" for both debug and release (selected from the "Make" drop down item). After clean -> run qmake -> build, Qt absolutely refuses to copy any of the files in "win32_libs" into the debug build directory.
If I specify just "win32_libs" instead of "win32_libs/*", it will copy the directory (not helpful), and it turns out it will copy any directory, but no files unless they are CONTAINED in a directory (again, not helpful).
So how can I convince it to just copy the files?
After facing similar problem and no being able to solve it directly I decided to do the workaround for the Windows target like:
# post build copy dependencies
win32 {
# all the necessary files listed relative to the root project directory
OTHER_FILES += stuff\myfile1 stuff\myfile2
OTHER_FILES += stuff\myfile3 stuff\myfile4
DESTDIR_WIN = $$DESTDIR
DESTDIR_WIN ~= s,/,\\,g
# debug pro file statement
message(Destination WINDOWS $$DESTDIR_WIN)
PWD_WIN = $${PWD}
PWD_WIN ~= s,/,\\,g
for(FILE, OTHER_FILES){
QMAKE_POST_LINK += xcopy /d/y $${PWD_WIN}\\$${FILE} $${DESTDIR_WIN}$$escape_expand(\\n\\t)
}
}
And xcopy command provided with parameters to avoid actual unnecessary copy.

Copy exe file to Qt build directory

I am trying to write a Qt application that will use QProcess to call ffmpeg.exe to convert media files. I cannot figure out the best way to make sure that the ffmpeg.exe file gets copied from my development directory to the build directory so that the built (and later deployed) application will have access to it.
I have seen information about using the INSTALLS parameter in my .pro file (https://stackoverflow.com/a/13168287) but the qmake docs say:
Note that qmake will skip files that are executable.
with all of the above said, how should one go about making sure that the exe file I want to use for QProcess ends up in the build directory (ready to be deployed later)?
You can use QMAKE_POST_LINK to execute a copy command when the application is built. Just put this in your .pro file :
win32:{
file_pathes += "\"$$PWD/Path/To/Files/ffmpeg.exe\""
CONFIG(release, debug|release):{
destination_pathes += $$OUT_PWD/release/
destination_pathes += Path/To/Deploy/Directory
}
else:CONFIG(debug, debug|release):{
destination_pathes += $$OUT_PWD/debug/
}
for(file_path,file_pathes){
file_path ~= s,/,\\,g
for(dest_path,destination_pathes){
dest_path ~= s,/,\\,g
QMAKE_POST_LINK += $$quote(xcopy $${file_path} $${dest_path} /I /Y $$escape_expand(\n\t))
}
}
}
You should add the paths for the files that you want to be copied to file_pathes variable and the paths to the destination directories to destination_pathes variable. Then all files would be copied to all the destinations when the application is built.
Here ffmpeg.exe gets copied to application build and deploy directories in release mode and to build directory in debug mode.

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

How do a specify a library file dependency for qmake in Qt?

Have a SomeLib.pro file that contains:
CONFIG += debug
TEMPLATE = lib
TARGET = SomeLib
..
Then in a dependent SomeApp.pro:
..
debug:LIBS += -lSomeLib_debug
..
How can I force SomeApp to build if I touched SomeLib in qmake?
It's ugly because you need to give the exact library file name, but this should work:
TARGETDEPS += libfoo.a
QT Creator will do the work if you click "Add library..." in the context menu of the project that should include the library.
These variables are configured automatically for you:
LIBS
INCLUDEPATH
DEPENDPATH
PRE_TARGETDEPS
See also http://doc.qt.digia.com/qtcreator-2.1/creator-project-qmake-libraries.html
In reply to Zahir's comment, it's perhaps worth pointing out that stating this dependency in qmake files is unnecessary if using DLLs, but is essential if your exe depends on a static library.
qmake does not provide this ability.
Instead, put your app and lib in subdirectories, then create a Makefile in their parent directory that looks something like this:
all: FRC
cd Somelib && qmake && $(MAKE)
cd SomeApp && qmake && $(MAKE)
FRC:
Then always run make from this directory.
I used:
POST_TARGETDEPS += c:/open-en/lib/win32mingw/libosal_based.a
It works, but is clumsy since it is necessary specify full path to library, which is different for every operating system/compiler.
surely that can't be possible, you are talking about using qmake to do a reverse dependency lookup? so what u want is for it to build app B (and any other app dependent on library A) after you've made a change to library A?
that's a bit like saying recompile all visual basic apps if vbrun300.dll is updated?