Page 2 of 2 FirstFirst 12
Results 21 to 38 of 38

Thread: QSettings with translation

  1. #21
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QSettings with translation

    Ahh, I am going crazy! First I thought the same, wysota, but before replying I had a quick look at the i18n example of the docs where they have the function
    Qt Code:
    1. void LanguageChooser::checkBoxToggled()
    2. {
    3. QCheckBox *checkBox = qobject_cast<QCheckBox *>(sender());
    4. MainWindow *window = mainWindowForCheckBoxMap[checkBox];
    5. if (!window) {
    6. QTranslator translator;
    7. translator.load(qmFileForCheckBoxMap[checkBox]);
    8. qApp->installTranslator(&translator);
    9.  
    10. window = new MainWindow;
    11. window->setPalette(colorForLanguage(checkBox->text()));
    12.  
    13. window->installEventFilter(this);
    14. mainWindowForCheckBoxMap.insert(checkBox, window);
    15. }
    16. window->setVisible(checkBox->isChecked());
    17. }
    To copy to clipboard, switch view to plain text mode 
    and thought (puzzled) that it would be possible. Now after having a closer look I understand the documentations code full and it isn't possible. Off course! Sometimes the examples are very trappy.

    Edit: Nice question style with the /* ??? */ comment and you haven't forgot to place it inside the code

  2. #22
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSettings with translation

    Quote Originally Posted by wysota View Post
    Franco, tell me, what is the value of "x" in the place marked with /* ??? */ in the following code? Could you explain why? As a hint - you can write a little program to test it:

    Qt Code:
    1. if(true){
    2. int x = 7;
    3. }
    4. /* ??? */
    To copy to clipboard, switch view to plain text mode 
    OK I understood, it was a 'out of scope' problem.
    Thank you


    Added after 8 minutes
    :

    Quote Originally Posted by Lykurg View Post
    Ahh, I am going crazy! First I thought the same, wysota, but before replying I had a quick look at the i18n example of the docs where they have the function
    Qt Code:
    1. void LanguageChooser::checkBoxToggled()
    2. {
    3. QCheckBox *checkBox = qobject_cast<QCheckBox *>(sender());
    4. MainWindow *window = mainWindowForCheckBoxMap[checkBox];
    5. if (!window) {
    6. QTranslator translator;
    7. translator.load(qmFileForCheckBoxMap[checkBox]);
    8. qApp->installTranslator(&translator);
    9.  
    10. window = new MainWindow;
    11. window->setPalette(colorForLanguage(checkBox->text()));
    12.  
    13. window->installEventFilter(this);
    14. mainWindowForCheckBoxMap.insert(checkBox, window);
    15. }
    16. window->setVisible(checkBox->isChecked());
    17. }
    To copy to clipboard, switch view to plain text mode 
    and thought (puzzled) that it would be possible. Now after having a closer look I understand the documentations code full and it isn't possible. Off course! Sometimes the examples are very trappy.

    Edit: Nice question style with the /* ??? */ comment and you haven't forgot to place it inside the code
    So why you (or the Qt developers ) offer example code containing errors?
    Last edited by franco.amato; 22nd October 2010 at 18:12.
    Franco Amato

  3. #23
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSettings with translation

    Can you point to the example containing errors?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #24
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSettings with translation

    Quote Originally Posted by wysota View Post
    Can you point to the example containing errors?
    Wysota the example posted by Lykurg contains similar code to what I posted yestarday and you commented with the little example
    Franco Amato

  5. #25
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSettings with translation

    Quote Originally Posted by franco.amato View Post
    Wysota the example posted by Lykurg contains similar code
    As I understand what Lykurg posted was to show a non-working example. Now you claim that we or Qt devs give bad examples so please point me to the bad example in Qt so that we may together see if it really is an incorrect example.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #26
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSettings with translation

    Quote Originally Posted by wysota View Post
    As I understand what Lykurg posted was to show a non-working example. Now you claim that we or Qt devs give bad examples so please point me to the bad example in Qt so that we may together see if it really is an incorrect example.
    The i18n example
    Franco Amato

  7. #27
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSettings with translation

    And what is wrong with it exactly?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #28
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSettings with translation

    Quote Originally Posted by wysota View Post
    And what is wrong with it exactly?
    The LanguageChooser::checkBoxToggled doesn't contain an error?
    Franco Amato

  9. #29
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSettings with translation

    No, it doesn't. Where do you see the error? That the translator object is created on the stack and goes out of scope? This is perfectly fine as it is no longer needed.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. #30
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSettings with translation

    Quote Originally Posted by wysota View Post
    No, it doesn't. Where do you see the error? That the translator object is created on the stack and goes out of scope? This is perfectly fine as it is no longer needed.
    So why in my case ( that the same code) it doesn't work?
    Franco Amato

  11. #31
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSettings with translation

    Because you delete the translator before it can do any of its work. Franco, trust me, if you don't go past pasting code from examples into your own programs, you will not make progress. You have to understand how things work before you start using them and not ask to have things explained to you (only) when the code you "borrow" doesn't work as you expect it to. Sometimes I think that the best we could do for you would be to stop answering your questions so that you were forced to do some research yourself. But I'm afraid that if not here then elsewhere you would find someone who would provide a working solution for you again preventing you from learning.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  12. #32
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSettings with translation

    Wysota sorry but I don't agree with you. I always search before ask here.
    So please tell me where is the difference.

    Franco code:
    Qt Code:
    1. if( QString::compare(m_language,"es") == 0 )
    2. {
    3. QTranslator esTranslator;
    4. esTranslator.load("ecpstudio_es");
    5. QCoreApplication::instance()->installTranslator(&esTranslator);
    6. }
    To copy to clipboard, switch view to plain text mode 

    Non_franco code:
    Qt Code:
    1. if (!window)
    2. {
    3. QTranslator translator;
    4. translator.load(qmFileForCheckBoxMap[checkBox]);
    5. qApp->installTranslator(&translator);
    6. //...more code
    7. }
    To copy to clipboard, switch view to plain text mode 

    because I really can't see the difference
    Franco Amato

  13. #33
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSettings with translation

    The difference is in what is hidden in "//...more code".

    Try to answer yourself this question: Why do you install a translator on an application?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  14. #34
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QSettings with translation

    Ok, since my post starts a new "stage" of discussion and to reply direct on
    Quote Originally Posted by franco.amato View Post
    So why you (or the Qt developers ) offer example code containing errors?
    some explanations:

    After post #18 I thought it is an out of scope problem. To prove that I looked up at the documentation at the i18n example. There I found the posted LanguageChooser::checkBoxToggled() function and due to a too fast and not carefully enough reading I misunderstood the code! I repeat: misunderstood. I thought that there the out of scope problem also have to occur. But it doesn't, so (wrong conclusion) Qt must copy the translator somehow and store it itself. This is the point where I should have dug deeper because I should have become suspicious of such a behavior of Qt. Though, my mind failed me. I took the voodoo-copying-no-out-of-scope-translator for real.

    After wysota's reply (#20) I wanted to write:
    Haha (in a sound of Nelson from the Simpsons), no it is not a out of scope problem because Qt does a voodoo-copying-no-out-of-scope-translator-thing!
    But before such a post I wanted to be sure, so I looked up the documentation again. And - surprise - I recognized my mistake while I read the code again. There I was angry at myself for not getting suspicious and for not doing further research. But I also realized that at that point the example is trappy (in the meaning that one could easily misunderstand the code), not wrong.

    So I just wanted to say, as a suggestion, that one could make the example code better. (and to say, that I am mad on me because for not reading carefully enough).


    - Everything clear now?
    - No!
    - Ok, but I am happy we have talked about


    And: The documentation is great and I love it. 99,99% of it. 0,01% could improved, thats all.

  15. #35
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSettings with translation

    As a matter of fact I think there are lots of examples that need improvement, review or throwing them to trash. Like the threaded fortune server example which makes people think they need to have multiple threads in their network servers. But to be honest:
    1. you should have looked in the docs for the example of i18n where the "trap" doesn't occur.
    2. QTranslator inherits QObject so obviously copying it... you know...
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  16. #36
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QSettings with translation

    Quote Originally Posted by wysota View Post
    But to be honest:
    Yes, you are absolutely right. Call it temporary black out, partial mental disease etc. Damn, it is like it is. *shame*


    Anyway. Sometimes this genius mind breaks out and searches for the possibility to express itself in the world of pictures After 1,5 years it happens again. This evening! While reading
    The difference is in what is hidden in "//...more code".
    I saw an image in my mind and must paint it. (It took me more than an hour, which is indeed a strong hint of a special kind of mental disease.) And since it does not matter if this thread has 35 or 36 (!) replies here it comes:
    pig-qtcentre.jpg

  17. #37
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSettings with translation

    Ha ha...a good one! Maybe you should be making a "Qt Centre comic book"? "Life of a Qt developer" or something...
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  18. #38
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSettings with translation

    Wysota and Lykurg thank you for your patience
    Franco Amato

Similar Threads

  1. UI translation
    By Annihilator in forum Qt Programming
    Replies: 2
    Last Post: 28th September 2010, 12:37
  2. translation
    By weixj2003ld in forum Qt Programming
    Replies: 8
    Last Post: 31st May 2010, 02:01
  3. Translation of UI
    By elizabeth.h1 in forum Qt Programming
    Replies: 1
    Last Post: 2nd November 2009, 12:01
  4. Migrate Qt3 QSettings to Qt4 QSettings
    By hvengel in forum Qt Programming
    Replies: 3
    Last Post: 22nd February 2008, 04:21
  5. Translation
    By merlvingian in forum Qt Programming
    Replies: 1
    Last Post: 14th August 2007, 18:45

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.