Qt install won't copy files - c++

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.

Related

Standalone Application Qt

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.

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

Copy Qt Libraries to output directory with make

I have a qt .pro file which looks something like this:
TEMPLATE = app
TARGET = demoqt
DESTDIR = ./debug
QT += core gui
CONFIG += debug
DEFINES += QT_LARGEFILE_SUPPORT QT_DLL
HEADERS += ./src/MainWindow.h
SOURCES += ./src/MainWindow.cpp ./src/main.cpp
Its building successfully under windows with the following .bat:
#echo off
echo Setting up a Qt environment...
set QTDIR=C:\Qt\4.8.3
set PATH=C:\Qt\4.8.3\bin;%PATH%
set QMAKESPEC=win32-msvc2010
call "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" amd64
qmake
nmake
I have absolutely no experience with makefiles what so ever - I completely winged this. The problem I'm experiencing is that the necessary Qt DLL files are not getting copied to the output directory. As such, when I execute my executable file, I get errors such as The program can't start because QtGuid4.dll is missing from your computer. Try reinsalling the program to fix this problem.
I would just add a line in the .bat file at the end to copy QtGuid4.dll (and any others) to the output directory.
If it's a personal project and you're not worried about installation/distribution issues, you can just copy them once manually to the Windows system directory (actual name depends on os version).

Automatic Copy of Dependent Files in Qt Creator

I've build a program using Qt Creator 2.2.1 and Qt 4.7.4 (32 bit) whose output is an executable. Opening the exe using DependencyWalker it shows that the exe uses following DLLs:
KERNEL32.DLL
MSVCRT.DLL
MINGWM10.DLL
LIBGCC_S_DW2-1.DLL
QTCORE4.DLL
QTGUI4.DLL
I want after the build all dependent files (which may be different in some other project) except Windows specific files (the first two in the above list) to be automatically copied in the directory where the exe is located.
How can I do it in Qt Creator or Qt system without using command line scripting? Thanks.
In QT 5.3, you may be able to use the windeployqt qt tool to automatically copy the needed libraries.
The following additions to the project's .pro file should do the trick, but you might have to make some adjustments based on your particular situation.
isEmpty(TARGET_EXT) {
win32 {
TARGET_CUSTOM_EXT = .exe
}
macx {
TARGET_CUSTOM_EXT = .app
}
} else {
TARGET_CUSTOM_EXT = $${TARGET_EXT}
}
win32 {
DEPLOY_COMMAND = windeployqt
}
macx {
DEPLOY_COMMAND = macdeployqt
}
CONFIG( debug, debug|release ) {
# debug
DEPLOY_TARGET = $$shell_quote($$shell_path($${OUT_PWD}/debug/$${TARGET}$${TARGET_CUSTOM_EXT}))
} else {
# release
DEPLOY_TARGET = $$shell_quote($$shell_path($${OUT_PWD}/release/$${TARGET}$${TARGET_CUSTOM_EXT}))
}
# # Uncomment the following line to help debug the deploy command when running qmake
# warning($${DEPLOY_COMMAND} $${DEPLOY_TARGET})
# Use += instead of = if you use multiple QMAKE_POST_LINKs
QMAKE_POST_LINK = $${DEPLOY_COMMAND} $${DEPLOY_TARGET}
I would modify your *.pro file for the project and use INSTALLS. To actually cause the files to be moved, you will need to run make install. In Qt Creator, you can add it as part of your normal build process by going into the "Projects" section and adding a new build step.
## This sets MY_LIB_FILES the libs you want and should also correctly resolve
## the location of the libs.
win32 { ## For Windows builds
# Note: Check to make sure of file name case
MY_LIB_FILES += $$QMAKE_LIBDIR_QT/MINGWM10.DLL
MY_LIB_FILES += $$QMAKE_LIBDIR_QT/LIBGCC_S_DW2-1.DLL
MY_LIB_FILES += $$QMAKE_LIBDIR_QT/QTCORE4.DLL
MY_LIB_FILES += $$QMAKE_LIBDIR_QT/QTGUI4.DLL
}
unix { ## For unix builds
# MY_LIB_FILES += $$QMAKE_LIBDIR_QT/...xxxxxx....
}
## Define what files are 'extra_libs' and where to put them
extra_libs.files = MY_LIB_FILES
extra_libs.path = $$DESTDIR
## Tell qmake to add the moving of them to the 'install' target
INSTALLS += extra_libs
Even though not totally automatic, you can with little effort do what you want with QtCreator.
Add the "INSTALLS" directive to your project (.pro) file (similar to what was suggested by jwernerny):
win32 {
libstocopy.files = $$QMAKE_LIBDIR_QT/MINGWM10.DLL \
... (add other files)
}
# If using MSVC the code may end up in "release" or "debug" sub dir
# Remove this if that is not the case
win32 {
CONFIG(debug, debug|release): OUTDIR = debug
else: OUTDIR = release
}
libstocopy.path = $$OUT_PWD/$$OUTDIR
INSTALLS += libstocopy
In the "Projects" tab of QtCreator (my version=2.4.1) you now add an extra build step:
Hit "Add Build Step"
Select "Make"
Leave "Override ..." empty
Enter "install" at "Make arguments:"
Since these settings are not saved with your project file you have to do the second part (Add Build Step) each time you create a new build configuration (e.g. one each for release and debug) or check out your project to a new location.
No-no-no 0_o :)
Create some directory to deploy files, i.e. "bin".
In every .pro file write
DLLDESTDIR = ../../myproject/bin (... some dir's struct ...)
QMAKE_POST_LINK = windeployqt --compiler-runtime $$DLLDESTDIR
DLLDESTDIR -- full path with file name TARGET (dll and exe).
End!