What is tr() function?
Holla qt masters,
I was reading chapter 4 (The main window) in book "Foundation of QT" . Following is the very first code in that chapter :
@SdiWindow::SdiWindow( QWidget parent ) : QMainWindow( parent )
setAttribute( Qt::WA_DeleteOnClose );
setWindowTitle( QString("%1 - %2" ).arg("unnamed"-).arg(-"SDI") );
docWidget = new QTextEdit( this );
setCentralWidget( docWidget );
connect( docWidget->document(), SIGNAL(modificationChanged(bool)),
this, SLOT(setWindowModified(bool)) );
statusBar()->showMessage( "Done" );
now author says in second para : "This explains parts of the command, but it
does not explain why the first string is in a call to tr or why you won’t use "unnamed[*] - SDI"
right away. You want to be able to support other languages (you’ll learn more in Chapter 10)"
well I don't see any call to tr() function. Anyways What is tr() and why should I worry about it?.
Also I couldn't understand why did he place  in line @setWindowTitle( QString("%1 - %2" ).arg("unnamed"-).arg(-"SDI") );@
My second question :
QAction has signal toggle(bool) , I don't understand what is the use of this signal? I mean in gui apps why would I use this signal? . Any example would be awesome .
Thanks a lot :)
the tr function is the central part of the Qt internationalization system (allso called "i18n" by people who can't handle words with more than ten letters). That's a system for making your application available in multiple languages.
If you want your application to have multiple language support, wrap every user-visible string in your code inside a tr() function. Then Qt will use the appropriate translated string in a different language environment. Of course Qt won't actually translate for you, you (or your translator guy) have to do that with QtLinguist.
the "[* ]" or more common "*" is just an old convention for window title bars for programs with a document- or project-concept. The window title bar shows the currently opened document/project and adds a star when there are unsaved changes in the document.
//EDIT: Overlooked the second question. Answer: QActions (e.g. represented as a menu item or a tool button) can be checkable. This means the tool button stays down once pressed or a check mark appears next to the menu item. The toggle signal allows you to see the new checked/toggle state in the signal parameters, so you can directly connect it to any slots taking boolean parameters. If you didn't have that, you'd need to create an intermediate slot that explicitly reads out the current checked state of that action and pass it on to the other slots that need the boolean.
bq. the “[* ]” or more common “*” is just an old convention for window title bars for programs with a document- or project-concept. The window title bar shows the currently opened document/project and adds a star when there are unsaved changes in the document.
so what's the new convention? . Also please answer my second question too?
I didn't mean that the convention is outdated. it's just well established. Personally I prefer appending " (unsaved changes)" or " (modified)" to the title. It's not like we have to save horizontal title bar space in times of 1920 pixels screen widths.
I just answered your second question seconds ago by editing my first post :)
Dear DerManu, I still didn't get what you said in your answer to my second question :
@QActions (e.g. represented as a menu item or a tool button) can be checkable@
I mean I never saw any UI where I can check the menu item Oo . Might be you can list/show me some practical example with images?
I really appreciate your help , thanks :)
A fairly common example may be that you may have an application that can show different tool-bars, like a document editor or web browser, for instance. You may have a View menu that lists several of them, and when they are checked they become visible, unchecked and they are removed.
[quote author="Mr.Anubis" date="1347717238"]
I mean I never saw any UI where I can check the menu item.[/quote]
I doubt it. You just didn't realize it.
!http://www.helpwithpcs.com/courses/windows-98-tutorial/desktop-arrange-icons.gif(checkable menu item example)!
or in thunderbird
Thanks a lot derManu :) , I now realize I've had seen it many times but couldn't map the feature in my mind.
Also notice that the QAction might not (only) appear on a menu, but could also appear on a toolbar or other places. You certainly have seen a toolbar button that stays down after clicking, right? That's the same as the checkbox in the menu.