Run uic for all .ui files in directory using windows batch - qt

I can get a list of Qt .ui files like so:
D:\programing\qtproject\ui\designer>dir *.ui /B
main.ui
mainmenu.ui
mainwindow.ui
And what I do right now is that I manually run uic for every one of them, because IDE I'm using (QtCreator, ironically the one IDE that should be perfectly compatible with Qt) is not capable of that.
So can I run uic with a list of files obtained from dir *.ui /B? I would prefer if this worked recursively on all subdirectories.

Ok, I cracked it using some helpful answers:
#echo off
rem Runs uic command over all files in all subdirectories
rem For loop arguments explained here: http://stackoverflow.com/a/3433012/607407
rem start command arguments explained here: http://stackoverflow.com/a/154090/607407
rem /B is why the start creates no additional windows: http://stackoverflow.com/a/324549/607407
for /f %%F in ('dir *.ui /S /B') do start "" /B "uic" %%F -o %%~dpFui_%%~nF.h
To disable the recursion (subdirectories), remove the /S parameter in the dir command.

Related

Creating Fat Jars: What is the mods folder?

I'm just on:
https://openjfx.io/openjfx-docs/#modular
trying to create a jar I can run on other systems (that do not have the javafx libraries as would happen with a non-developer layman user) and they've told me to use this:
dir /s /b src\*.java > sources.txt & javac --module-path %PATH_TO_FX% -d mods/hellofx #sources.txt & del sources.txt
What is mods/
Where is that supposed to be? Are they talking about out/ ?
The doc you have linked refers to this sample.
If you clone the sample, and follow instructions on how to compile and run the project, the first command can be divided in three parts:
dir /s /b src\*.java > sources.txt & \
javac --module-path %PATH_TO_FX% -d mods/hellofx #sources.txt & \
del sources.txt
The first part just gets all the Java files in the src path and adds that to sources.txt file:
C:\path\to\hellofx\src\module-info.java
C:\path\to\hellofx\src\hellofx\HelloFX.java
The second part calls the javac command (see reference) to compile the content of sources.txt, adding the required --module-path option to include the JavaFX modules, and also adding the output or destination -d option:
-d directory
Sets the destination directory for class files. If a class is part of a package, then javac puts the class file in a subdirectory that reflects the package name and creates directories as needed.
This means that we are going to compile hellofx.HelloFX.java into the directory mods/hellofx, resulting in:
C:\path\to\hellofx\mods\hellofx\module-info.class
C:\path\to\hellofx\mods\hellofx\hellofx\HelloFX.class
The third step will just remove the sources.txt file.
And now you can run your module:
java --module-path "%PATH_TO_FX%;mods" -m hellofx/hellofx.HelloFX
You can specify any directory for the output, of course, so you can change it to out or build for instance, but then make sure you modify it accordingly in the rest of the instructions.

Generate Makefile with clean rule that removes project executable

I want my QtCreator project to have a Makefile with a "make clean" rule that deletes the executable.
Normally, when making a Makefile for a simple C++ project, I would put this rule in the Makefile, where neatprogram is the executable (on Linux):
clean:
rm -f neatprogram
But QtCreator uses qmake to generate a Makefiles for me. By default, it even adds a clean rule to the Makefile! But it only removes object files and such. How can I make it so the Makefile generated by qmake also removes (deletes) the single executable file for my program?
There's a predefined target distclean which removes all generated files including an executable. But note that Makefile itself will also be removed.
Alternatively, you can define your own target like this:
myproject.pro
QMAKE_EXTRA_TARGETS += myclean
#myclean.target = myclean
myclean.depends = clean
myclean.commands = -$(DEL_FILE) $(DESTDIR_TARGET)

How to use existing QMake project (.pro project file) as "external project" in CMake?

Is there a concise doc or example for how to use an existing QMake project with .pro project file as an "external project" in CMake? This can somewhat be done in qtcreator by marking one project as dependency of another, but it would be nice to define it more explicitly with the ExternalProject() CMake syntax.
related question: CMake: How to build external projects and include their targets
Something like this works. You can then edit the files from either qtcreator in main CMake project tree, OR from opening the .pro file; great for iterating quickly on QT widgets in SomeGarbageApplication that is part of large cmake build tree.
macro(DeclareProjectFiles Tag Filez)
######### Trick: use this syntax to make arbitrary files
######### appear in IDE project. #######################
### Note: pass in the raw name of a list variable,
### since it will get expanded here in this macro.
add_custom_target(${Tag}_files ALL
pwd
COMMAND ls -ltrh
COMMENT " ${Tag} files thunk... got list: [ ${${Filez}} ]"
VERBATIM
SOURCES ${${Filez}}
)
endmacro()
message(STATUS "QT_QMAKE_EXE is: ${QT_QMAKE_EXECUTABLE}")
set(Z SomeGarbageApplication)
file(GLOB ${Z}_Files
./*.cpp
./*.h
./*.ui
./*.pro
./*.png
./*.jpg)
DeclareProjectFiles( ${Z}_grbg ${Z}_Files )
add_custom_target(${Z}_pro ALL)
set(ExtraQMakeArgs -r -spec linux-g++ CONFIG+=release)
# note: use killall because this can/will fail if the exe is running
# But, need || true to not fail build when it's not running.
add_custom_command(TARGET ${Z}_pro
COMMAND killall
ARGS -q -9 -v ${Z} || true
COMMAND ${QT_QMAKE_EXECUTABLE}
ARGS -query
COMMAND ${QT_QMAKE_EXECUTABLE}
ARGS ${CMAKE_CURRENT_SOURCE_DIR}/${Z}.pro ${ExtraQMakeArgs}
COMMAND make ${Z}
ARGS -j4
COMMAND cp
ARGS ${Z} ${CMAKE_CURRENT_SOURCE_DIR}/${${Z}_config} ${CMAKE_BINARY_DIR}/bin/
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
VERBATIM
)
#################################################################

QMake SUBDIRS project: How to call release-clean from top-level Makefile?

I am using a Qt .pro file using the SUBDIRS template (mainly following this answer).
Furthermore I am building my solution using qmake -recursive MyProject.pro and nmake Release.
Now I want to supply a separate batch file for cleaning up the release output and meta files (not the debug ones though).
The problem is that for the top-level Makefile, only clean and distclean is generated by qmake while for the subdirectories, there are also release-clean and debug-clean (also the folders contain an additional Makefile.Debug and Makefile.Release).
What I want to do is calling
nmake Makefile release-clean
from the batch script. However the top-level makefile does not contain this configuration.
Now I could call the equal line for every subproject manually but this is obviously my least favoured option.
Is there a way to either get qmake to generate a release-clean target for the top-level makefile or is there another way to simply clean release files?
PS: I'm using nmake, so yes I'm on Windows (XP) and using MSVC (2008)
The following batch script does the job :
REM set up environment
SET VISUALDIR=C:\PROGRA~1\MICROS~1.0
PUSHD %VISUALDIR%\VC
CALL vcvarsall.bat x86
POPD
REM clean solution
msbuild yoursolution.sln /p:Configuration=Release /t:clean
REM and you may want to add a build command :
msbuild yoursolution.sln /p:Configuration=Release
Ever tried nmake Makefile.Release clean, that should do the job.

Using Qt Creator and Project files, how do I copy a created dll/so with QMAKE_POST_LINK

This question appears to be answered in this tread
qmake: How do I copy .dll/.so's to the output directory?
but it does not work for me. I'm trying to do this within Qt Creator 2.0.1 with Qt SDK 4.7.0 on Windows 7
If I try:
QMAKE_POST_LINK=copy /Y \Projects\TestFile.txt \Projects\OSPF\TestFile.txt
on even a static file, the output I get is:
copy /Y \Projects\TestFile.txt \Projects\OSPF\TestFile.txt
process_begin: CreateProcess(NULL, copy /Y \Projects\TestFile.txt \Projects\OSPF\TestFile.txt, ...) failed.
make (e=2): The system cannot find the file specified.
If I try:
QMAKE_POST_LINK=cmd.exe /C copy /Y \Projects\TestFile.txt \Projects\OSPF\TestFile.txt
The output I get is:
cmd.exe /C copy /Y \Projects\TestFile.txt \Projects\OSPF\TestFile.txt
The system cannot find the file specified.
Does someone know the answer to this?
As the error message suggests the problem is in the path to the file you want to copy.
I created a simple .pro file and used the same command to copy a file - with the path changed accordingly - and it worked correctly.
QMAKE_POST_LINK=copy /Y .\hello.h .\debug\hello.h;
it's equivalent to
QMAKE_POST_LINK=copy /Y hello.h debug\hello.h;
With this command the file hello.h, in the same directory of the .pro file, is copied to the debug folder.
I got it!
Apprently the copy does not work if you start at the root of your drive. Go back and look at my example. I was starting at the root of my current drive. I also tried
QMAKE_POST_LINK=copy /Y $$PWD\MyFile $$PWD\anotherdir\MyFile
That did not work either.
Apprently you have to be relative to you directory???? I'm not sure what the real limitations are.

Resources