I'm new in the world of Qt/PyQt/QML.
I'm creating a simple calculator using PyQt5 and QML.
In QML title is assigned by like below instead of a string.
title : qsTr("PyQt5 Love QML")
I've no idea what is the use of qsTr and What is the advantage of it.
qsTr is for localization purposes. Later it will help Qt to gather strings to be translated to different languages. It is a common and recommended practice to wrap all the gui-strings in your code in qsTr (or just tr in case of C++/Qt) since then special Qt's tools like lupdate and lrelease could prepare nice translation files for you.
So, even if you do not plan to localize your app, it is recommended to wrap any string that will be displayed to user in qsTr to get a usefull habit.
Related
I've implemented language support in an application I've been writing which outputs data in JSON objects which is viewable using a separate web interface which reads the JSON objects. No matter what language I am using, I want to be able to output the English (default string passed to the tr() macro). Is there an easy way to get this? It seems like what I'm after is the opposite to the tr() macro?
Thanks in advance.
I am trying to develop a Qml based QT application which will support multiple languages.In the application there will be drop down list from where on select of language whole language family of the application will be changed.Can anyone help me on that giving idea how to proceed?
Is there any example? and is QTranslator() is the convenient way to do this?
The localization system of Qt is well documented: Internationalization with Qt
Simply you put your text directly in the C++ code, using the tr() method of QObject (or qsTr() in QML). Than there are some tools (lupdate and lrelease) to generate the translation files. I suggest to read the documentation, it's very easy.
Some useful links:
Hello tr: and example
Qt Linguist manual
QTranslator works well with Qt UI as you can use languageChanged() signal to update the UI. This isn't possible with QML.
See this QML WiKi, it is the recommended workaround (for now!).
I would like to add a new language (called 'kiwi') into the Brackets code editor which is based on C++. It uses the exact same rules but has additional keywords.
I've already done the part of adding the additional keywords with separate syntax highlighting directly on the clike.js file but i don't really like directly modifying the def for C++
Can someone explain to me how I can achieve this? I don't really understand the difference between using def() and CodeMirror.defineMIME(). If this new language will take cpp/hpp input files, how will the editor switch from C++ -> kiwi?
Thanks in advance
Patching your local copy of the code, as you've done, might be perfectly fine for your needs. (And if you run from a Git copy of the source, it's easy to pull down updates without losing your local diffs).
If you want to do it a "cleaner" way, you can write a Brackets extension to define the new language - this way the change is easily shareable with others, and updating Brackets is even easier.
The way you'd do this roughly follows the Defining a new language docs:
Write an extension to package up your code that will define the new language (below)
The CM mode "clike" is already loaded, so you don't need to worry about that
Call CodeMirror.defineMIME() to set up a clike configuration with the right list of keywords - using a new mimetype name of your choosing. (Looking at the def() code in clike.js, I don't think the extra stuff it does is especially relevant for Brackets).
Call LanguageManager.defineLanguage() to tell Brackets about your new language mode (and what file extensions map to it, etc.). You should be able to mostly copy how the C++ mode is defined here - except with your new MIME name instead.
You should read CodeMirror documentation to find out about writing your modes.
But in short you can define your own type of clike language, by using CodeMirror.defineMIME().
You also asked what's the difference between def() and CodeMirror.defineMIME(). If you look at the code you can see that def() function is calling CodeMirror.defineMIME() at the end, so I believe it is just a more readable way of defining the type.
Also it seems that it's impossible to define more than one language on the same extension type (not 100% sure).
Im learning how to use QT's translate stuff for the first time for work.
They already have things working to some degree and its my job to clean
things up and get it working properly as well as using lupdate to keep
things in sync when they change etc. We are also using QML in which we
wrote a wrapper function for all our strings, so lupdate does not find
our function to add to the .ts XML file. The reason we use a wrapper is
for centralizing other functions at once place for all strings. We also
dont always use a string literal in our 'source' argument but a defined
property, such as:
property string buttonTxt: "ButtonText"
then: commonTRFunction(context, buttonTxt)
which of course lupdate does not find for both reasons.
Ive looked into updating the lupdate source very briefly
and Im not sure if its worth trying to hack it to find our function or
write our own parser to find the standard QT tags AND also our new ones?
Secondly, and related to the first part, Id like a way to make one
context section that contains all the common words we use in our app
such as 'Back', 'Save', 'Ok' etc etc without repeating it over and over
throughout the .ts file. lupdate seems to repeat things over and over
in multiple contexts which seems both inefficient and a waste of lines
in the ts file.
I haven't found any QT docs that really explain the differences between tr(), qsTr(), qsTranslate(), QT_TR_NOOP() and QT_TRANSLATE_NOOP(). I know you sometimes need a context and the source,
and other times just use the source without a context. We dont use
the disambigous arg. Most of our code is in QML and not C++.
Also we are running lupdate from the command line.
Does anyone have thoughts, suggestions or even a tool someone wrote
that can be used for what we have? I appreciate your help.
i need to generate a GUI for a ready code written with C++ the code is divided into some classes containing one that represent user interface to facilitate generating GUI without big modifications on my code
and i already designed the GUI window using QT Designer
now i want to link both logical part (my classes)and GUI part(QT Designer output class) ,how to add all classes to the GUI,how to handle signals coming from GUI and send the appropriate input to the logical part
GUI
get some words from user
get slider input as an int
add files from HDD (logical part need full paths)
out some text
NOTE:first time with QT
thanks in advance for any help
You might want to start with these simple tutorials
http://www.qttutorial.com/qt/hello-qt-your-first-application/
http://www.qttutorial.com/qt/hello-qt-your-first-qt-application-part-2/
I you need a really simple solution - call this in desired order:
QInputDialog::getText();
QInputDialog::getInt();
QFileDialog::getOpenFileName();
QMessageBox::information();
QtAssistant should give you much more details and examples.