I want to run lupdate and lrelease command from qtcreator at the time of build.
Is it possible?
If yes then how?
Note: I am using lupdate and lrelease command from linux terminal and its working fine but i want to run these commands from qt creator at the time of build.
Assuming you're using qmake, you should use the TRANSLATIONS variable:
https://doc.qt.io/qt-5/qmake-variable-reference.html#translations
This page has some examples:
HEADERS = main-dlg.h \
options-dlg.h
SOURCES = main-dlg.cpp \
options-dlg.cpp \
main.cpp
FORMS = search-dlg.ui
TRANSLATIONS = superapp_dk.ts \
superapp_fi.ts \
superapp_no.ts \
superapp_se.ts
The Hello tr() Example explains the process in more detail:
Note that the file extension is .ts, not .qm. The .ts translation
source format is designed for use during the application's
development. Programmers or release managers run the lupdate program
to generate and update TS files with the source text that is extracted
from the source code. Translators read and update the TS files using
Qt Linguist adding and editing their translations.
[...]
Once the translations are complete the lrelease program is used to
convert the TS files into the QM Qt message file format. The QM format
is a compact binary format designed to deliver very fast lookup
performance. Both lupdate and lrelease read all the project's source
and header files (as specified in the HEADERS and SOURCES lines of the
project file) and extract the strings that appear in tr() function
calls.
lupdate is used to create and update the message files (hellotr_la.ts
in this case) to keep them in sync with the source code. It is safe to
run lupdate at any time, as lupdate does not remove any information.
For example, you can put it in the makefile, so the TS files are
updated whenever the source changes.
in your Qt Creator, go to Projects > Build Steps
there you can add two Custom Process Steps with your commands lupdate and lrelease
Related
In the documentation of the Qt lrelease tool I read, that .ts files can be compiled to .qm binaries using following command:
lrelease.exe main_en.ts languages\main_fr.ts
Is it possible to take .xliff files as well as input instead of the .ts files to compile .xliff files to .qm files? How is it done?
From the documentation of lupdate, it is mentioned that you can generate .ts file from XLIFF files. You can then use lrelease to generate the .qm file.
Be aware that only the XLIFF 1.1 format is supported, not the 1.0.
To convert a xliff file to ts, you can use the lconvert utility with a command line like this:
lconvert -o converted.ts -i original.xlf
Here is the output of lconvert -help:
Usage:
lconvert [options] [...]
lconvert is part of Qt's Linguist tool chain. It can be used as a
stand-alone tool to convert and filter translation data files. The
following file formats are supported:
qm - Compiled Qt translations
pot - GNU Gettext localization template files
ts11 - Qt translation sources (format 1.1)
ts20 - Qt translation sources (format 2.0)
qph - Qt Linguist 'Phrase Book'
ts - Qt translation sources (latest format)
po - GNU Gettext localization files
xlf - XLIFF localization files
If multiple input files are specified, they are merged with
translations from later files taking precedence.
Options:
-h
--help Display this information and exit.
-i <infile>
--input-file <infile>
Specify input file. Use if <infile> might start with a dash.
This option can be used several times to merge inputs.
May be '-' (standard input) for use in a pipe.
-o <outfile>
--output-file <outfile>
More info here about this Qt tool
I'm trying to determine the build directory in the qmake project file, but failed in all my experiments so far :-(
At first I had a very plain foo.pro as QtCreator generates it for a plain Qt5 gui app with a few source files. Then I added an EXTRA_BINFILES list with some data files. They must be copied in the same directory as the executable foo. Without the copy stuff, it looks like this:
QT += core gui xml webkitwidgets widgets
TARGET = foo
TEMPLATE = app
EXTRA_BINFILES += \
foobar.png \
baz.png
SOURCES += \
main.cpp \
# ...
HEADERS += \
# ...
FORMS += \
# ...
When I build that, I get the foo executable (or foo.exe if you want). Mostly straightforward so far. Now I want to copy the EXTRA_BINFILES alongside this executable. The open question is how to get the destination directory. My best idea so far is adding this:
for(FILE, EXTRA_BINFILES) {
QMAKE_POST_LINK += $$quote($${QMAKE_COPY} $$shell_path($${PWD}/$${FILE}) $$shell_path($${OUT_PWD})$$escape_expand(\n\t))
}
This uses the OUT_PWD variable, which automatically points to where the Makefile is generated. This is nice for some scenarios. However, I have to deal with two different scenarios:
Directly compiling from within QtCreator with mostly out-of-the-box build configs. It creates a new build-foo-desktop-release directory, creates the Makefile there and builds the executable there. In this scenario, everything works fine.
Building from command-line with qmake -makefile /my/projects/foo/foo.pro and make in a temporary fresh build directory. This way it creates the Makefile in directly in that build directory but compiles the executable into a release subdirectory`. This obviously breaks my copy code.
For some reasons, it is not an option to get rid of one of those scenarios. I have to deal with both of them within the same project file. It is also not an option to make very technical/tricky things in the project file. It has to remain mostly as 'straightforward' as it is. Overriding some of qmake's own variables in the qmake command-line call is also probably not an option. This is because of the broader context, which is too extensive to explain here.
Is there an option to get the correct path in both scenarios? Something like OUT_PWD but for the executable itself?
Unfortunately, DESTDIR is empty (and as mentioned, it is not an option to forcefully set it). DESTDIR_TARGET is empty as well (otherwise I could combine it with dirname, which would be barely non-tricky enough).
Any hints?
sub_dir = $$_PRO_FILE_PWD_
sub_dir ~= s,^$$re_escape($$PWD),,
PROJECT_BUILD_TREE = $$clean_path($$OUT_PWD)
PROJECT_BUILD_TREE ~= s,$$re_escape($$sub_dir)$,,
I want to build qt application that will gather all the necessary binaries for standalone execution on install.
I know that can be done in lines of:
QT_DIR=C:/Qt/4.8.4
dlls_to_move.files += $$DIR/bin/QtCore.dll
however that seems clumsy. Is there a way to retrieve Qt binary folder actually used, like project directory that can be retrieved with $$PWD?
From qmake Advanced Usage:
The special $$[...] operator can be used to access various configuration options that were set when Qt was built:
So I think you'd want to do this in your project file:
dlls_to_move.files += $$[QT_INSTALL_BINS]/QtCore.dll
I'm trying to create a simple Qt project. I have done inside of a folder the following:
Created a .ui file
ran qmake -project
Made a .pro file
Made a main.cpp file
How can I run this project using a command line?
You probably should run qmake to generate a Makefile from your .pro, then run make to compile and build the executable binary program, then run that program by its name. You might need to type the full or relative file path of the program if your PATH is not containing the directory having the program binary.
I have 4 files
message.proto
udp.h
udp.cpp
main.cpp
message.proto is a google protocol buffer file. I am trying to write a protocol buffer and send and receive data using UDP. udp.h and udp.cpp are just classes to implement UDP.
I can write my own makefile and do the needful for this small example. Later I would require to integrate this code into my QT program. I am using qmake -project, qmake to generate the Makefile. I am using Ubuntu 9.10
Could some one tell me the changes I need to make in the .pro file or the Makefile generated by qmake to satisfy the dependencies.
Usually you just need to add the respective header and source files to the corresponding HEADERS and SOURCES variables in the .pro file, i.e.
SOURCES += udp.cpp message.pb.cc
HEADERS += udp.h message.pb.h
where I implicity assumed that message.pb.cc and message.pb.h are the files generated by protoc (the protocol buffer compiler). If you additionally want the generated makefile to run protoc for you, you can accomplish that with the system function (http://doc.trolltech.com/4.6/qmake-function-reference.html#system-command).
I hope that helps.