Results 1 to 20 of 20

Thread: Translation problems

  1. #1
    Join Date
    Oct 2009
    Posts
    19
    Thanked 1 Time in 1 Post

    Exclamation Translation problems

    Hello everyone; I'm new at the forum, and I need some help with translations.

    I've made a minimal application for testing translations before going on production, and I realised that its not working. I did it as some tuts said and using c++ qt programming guide as guideline, but I'm still getting the error "instantiate QApplication object first" and what is most strange is that im only seen it (the message) when debugging with gdb. Of course translations are not working, and the text appears in its original language (spanish).
    Im running on windows xp with mingw, qt4.5.1. I haven't tested it in Linux yet but from now on I've not had problems with this (linux windows, windows linux)
    Here is my code:
    Qt Code:
    1. int main(int argc, char *argv[]){
    2. QApplication *myApp = new QApplication(argc, argv, true);
    3. QWidget *mainWindow;
    4. QString *trstring;
    5. QLabel *theLabel;
    6. QGridLayout *theGridLayout;
    7. QTranslator theTranslator;
    8.  
    9. theGridLayout = new QGridLayout(0);
    10.  
    11. trstring = new QString(QApplication::tr("Hola"));
    12. theLabel = new QLabel(0);
    13. theLabel->setText(*trstring);
    14.  
    15. if(!mainWindow->centralWidget())
    16. mainWindow->setCentralWidget(new QWidget(0));
    17.  
    18. theGridLayout->addWidget(theLabel, 0, 0, Qt::AlignLeft);
    19. mainWindow->centralWidget()->setLayout(theGridLayout);
    20.  
    21. if(!theTranslator.load("englishTranslations", QDir::currentPath()+"/translations"))
    22. exit(0);
    23. myApp->installTranslator(&theTranslator);
    24. mainWindow->show();
    25. return (myApp->exec());
    26. }
    To copy to clipboard, switch view to plain text mode 

    I don't know why is it failling, I've added the TRANSLATIONS line to the .pro file, and I've done the lupdate and lrelease execution with success. And later the translation with the liguist utility.

    What I'm missing ? What could be wrong ? Is it so difficult ? Everyone seems to be doing it as something quite simple....

    Thanks, regards

    Nahuel
    Last edited by Skepsor; 27th October 2009 at 13:54. Reason: Change icon

  2. #2
    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: Translation problems

    1. Create the application object on the stack.
    2. You are not creating the main window anywhere but you are using it (hence the app should immediately crash - if it doesn't it means you create the window somewhere else before QApplication object is created).
    3. Actually it shouldn't even compile as your mainWindow variable is a QWidget and you use it as if it were QMainWindow. If it compiles, it means that you have given us the wrong code.
    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.


  3. #3
    Join Date
    Oct 2009
    Posts
    19
    Thanked 1 Time in 1 Post

    Exclamation Re: Translation problems

    Oh sorry....I added some things in the way.
    Here the right code:

    Qt Code:
    1. int main(int argc, char *argv[]){
    2. QApplication *myApp = new QApplication(argc, argv, true);
    3. QMainWindow *mainWindow;
    4. QString *trstring;
    5. QLabel *theLabel;
    6. QGridLayout *theGridLayout;
    7. QTranslator theTranslator;
    8.  
    9. mainWindow = new QMainWindow(0, Qt::Widget);
    10. theGridLayout = new QGridLayout(0);
    11.  
    12. trstring = new QString(QApplication::tr("Hola"));
    13. theLabel = new QLabel(0);
    14. theLabel->setText(*trstring);
    15.  
    16. if(!mainWindow->centralWidget())
    17. mainWindow->setCentralWidget(new QWidget(0));
    18.  
    19. theGridLayout->addWidget(theLabel, 0, 0, Qt::AlignLeft);
    20. mainWindow->centralWidget()->setLayout(theGridLayout);
    21.  
    22. if(!theTranslator.load("englishTranslations", QDir::currentPath()+"/translations"))
    23. exit(0);
    24. myApp->installTranslator(&theTranslator);
    25. mainWindow->show();
    26. return (myApp->exec());
    27. }
    To copy to clipboard, switch view to plain text mode 

    What do you mean with the first point ?
    1. Create the application object on the stack. ?

    Please heelp!

    Thanks
    Last edited by Skepsor; 27th October 2009 at 13:40.

  4. #4
    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: Translation problems

    I mean create it on the stack and not on the heap like you do now.

    http://www-numi.fnal.gov/offline_sof..._and_heap.html

    Also please state if you have any static or global objects.
    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.


  5. #5
    Join Date
    Oct 2009
    Posts
    19
    Thanked 1 Time in 1 Post

    Default Re: Translation problems

    Thanks for the reply.
    Respect the static or global objects, i must said that what you see is what you get . That is the code im trying, theres nothing else.
    Well the stack creation as I understand neither is working.
    I've tried:
    Qt Code:
    1. QApplication app(argv, argc, true);
    2. QApplication *myApp;
    3. myApp = &app;
    To copy to clipboard, switch view to plain text mode 
    and later using the pointer myApp.

    and also tryied:
    Qt Code:
    1. QApplication app(argv, argc, true);
    To copy to clipboard, switch view to plain text mode 
    and later using directly app.

    If this is wrong, very very wrong, It would be nice if you could just type how to do it

    Thanks



    Thanks.
    Last edited by Skepsor; 27th October 2009 at 15:09.

  6. #6
    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: Translation problems

    I'm sure there is at least a bunch of include statements.
    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.


  7. #7
    Join Date
    Oct 2009
    Posts
    19
    Thanked 1 Time in 1 Post

    Default Re: Translation problems

    No, theres not bunch of includes.

    take a look

    #include<iostream>
    #include<QtGui/QApplication>
    #include<QtGui/QMainWindow>
    #include<QtCore/QString>
    #include<QtGui/QLabel>
    #include<QtGui/QGridLayout>
    #include<QtCore/QTranslator>

    Regards

  8. #8
    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: Translation problems

    To be honest I don't get any warnings from your code (although I'm running Linux). Are you sure this is the same code you get warnings from?
    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.


  9. #9
    Join Date
    Oct 2009
    Posts
    19
    Thanked 1 Time in 1 Post

    Default Re: Translation problems

    No, you wont get any message, because as I said first the message appears with gdb, at least in xp. The mainly situation is if it's enought with this code to use translations, lets say.....can you make it work copying and pasting my code ? and generating the ts and qm files?
    Do you (or someone else) have some actual simple working code ? I'm kind of disappointed with it, because it should work, it must work, in fact, it must work with the first code I post, because thats how everybody is doing it, in the web, in the tuts, everywere, nobody is talking about stack or heap creation, they just do as I do just that my code is not working....jeje

    Thanks for the attention, hope we can solve it, I'll be here

    Regards

  10. #10
    Join Date
    Oct 2009
    Posts
    19
    Thanked 1 Time in 1 Post

    Thumbs up Re: [SOLVED] Translation problems

    Well it seems to be that I have found the problem, but I'd like someone to explain why do I get this beheaviour.
    The problem is with the .pro file, in one of its lines I could see comething like...

    CONFIG = qt warn_on release

    I took off the release word and it works ! and if I use the debug option also works....but now I want to know why is not working in release ? What is changing ? Which are main differences between release and debug and whe shoul I use one and when another.

    Thanks for all, regards

    Nahuel

  11. #11
    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: [SOLVED] Translation problems

    But what exactly is not working (I got a bit confused) - the translations?
    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. #12
    Join Date
    Oct 2009
    Posts
    19
    Thanked 1 Time in 1 Post

    Default Re: Translation problems

    Yes yes, ofcourse wht is NOT working are translations, but I could handle it taking off the release option from the CONFIG variable in the .pro file. What I'd like to know is why is it happening....?

  13. #13
    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: Translation problems

    You are using relative paths for your translation files so probably Qt just can't find them if you start the application from another directory.
    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. #14
    Join Date
    Oct 2009
    Posts
    19
    Thanked 1 Time in 1 Post

    Default Re: Translation problems

    No man, no no no, it seems you're not reading well, or you're not reading.....lets see....lets start again.

    - The main problem was with translations. They weren't working, my text wasn't getting translated.
    - I discovered that taking off the option 'release' from the CONFIG directive of the proyect file makes it work.
    - Translations now work, but....

    Please avoid thinking weird stuff, as running app in another place, or anythings that comes up to your imagination.......is simple

    What I want to know NOW, before creating another thread....is WHY the translations doesn't work if I have setted the 'release' option in the CONFIG directive of my proyect.

    Is it clear now ?

    Regards

  15. #15
    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: Translation problems

    Quote Originally Posted by Skepsor View Post
    - I discovered that taking off the option 'release' from the CONFIG directive of the proyect file makes it work.
    - Translations now work, but....
    How do you start the application then? By double clicking its icon? Where is the application binary, in what directory? Is it the same for release and debug? Because usually on Windows these land in different directories. It might be that you have two versions of the translations, one translated and the other not. Please check that.

    Please avoid thinking weird stuff, as running app in another place, or anythings that comes up to your imagination.......
    That's not weird stuff. Please state the directory structure of your application.

    Is it clear now ?
    It has been clear since some time.
    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. #16
    Join Date
    Oct 2009
    Posts
    19
    Thanked 1 Time in 1 Post

    Default Re: Translation problems

    Hello
    How do you start the application then? By double clicking its icon? Where is the application binary, in what directory? Is it the same for release and debug? Because usually on Windows these land in different directories. It might be that you have two versions of the translations, one translated and the other not. Please check that.
    myApplication.exe [Enter]
    In the same directory of the eclipse proyect.
    Yes I guess is the same for release and debug, I'm not getting two binaries.
    I don't have two translated versions.

    I'm gonna expose a new view:
    I created an eclipse proyect.
    Then I did:
    qmake -o Makefile -win32 myProyectFile.pro
    Then I edited the .pro and I added CONFIG = qt warn_on release
    Then:

    make all
    So, in the end I got this:
    myProyectFile.pro
    Makefile
    debug\ (folder)
    release\ (folder)
    translations\myTranslationFile.ts
    translations\myTranslationFile.qm
    myBinaryApp.exe
    Tha's all, and I run with:
    C:\Proyect\myBinaryApp.exe [Enter].

    Right? And now ? Why is the release option making my app not being translated?

    Thanks and regards

  17. #17
    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: Translation problems

    Please provide a minimal compilable example (with project file and translations) reproducing the problem.
    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. #18
    Join Date
    Sep 2009
    Location
    Nanjing, China
    Posts
    46
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Translation problems

    I'd like to read your code. I also got translation problems and I found it only if the class has the macro Q_OBJECT, it could be translated. If you could not put out your code I suggest you to read Qt assistant's document.

  19. #19
    Join Date
    Aug 2008
    Location
    Algarve, Portugal
    Posts
    288
    Thanks
    23
    Thanked 32 Times in 28 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: Translation problems

    This program works fine under linux but doesnt work on Windows.
    I had the same problem and it's because of this line
    Quote Originally Posted by Skepsor View Post
    Qt Code:
    1. .......
    2. if(!theTranslator.load("englishTranslations", QDir::currentPath()+"/translations"))
    3. exit(0);
    4. .......
    5. }
    To copy to clipboard, switch view to plain text mode 
    In windows you start your program from the debug or release folder, not like linux wich runs from the project directory. Just copy the translations directory to your debug or release directory and it will be fine, that way you can maintain "linux compatibility". And when you deploy it just put the translation folder as a sub folder from your directory's .exe file.
    Last edited by john_god; 13th November 2009 at 01:16.

  20. #20
    Join Date
    Oct 2009
    Posts
    19
    Thanked 1 Time in 1 Post

    Default Re: Translation problems

    Hello all, thanks for your replies and sorry for my delay .
    I finally did it work, but don't remember how. What is for sure is that I re-configured the .pro file adding the debug_and_release option, and configured it to put the resulting apps into diffrent dirs with the following code:
    Qt Code:
    1. CONFIG(release, debug|release){
    2. DESTDIR = release/
    3. TARGET = designer }
    4. else {
    5. DESTDIR = debug/
    6. TARGET = dbgDesigner
    7. }
    To copy to clipboard, switch view to plain text mode 

    Also I copied the translations/ directory to debug and release folders to avoid doubtsa bout problems loading files, or different versions of translations. I also changed the line that john_god details above. I guess all that did the trick

Similar Threads

  1. Translation for plugins
    By gustavosbarreto in forum Qt Programming
    Replies: 0
    Last Post: 14th August 2009, 13:25
  2. Problems to display a QFont in a View/Model correctly
    By NoRulez in forum Qt Programming
    Replies: 0
    Last Post: 8th July 2009, 12:26
  3. Replies: 2
    Last Post: 8th March 2007, 22:22
  4. QT4 Plugins - problems, problems
    By NormanDunbar in forum Qt Programming
    Replies: 6
    Last Post: 9th May 2006, 15:39
  5. Splitting Translation Files
    By Jimmy2775 in forum Qt Programming
    Replies: 9
    Last Post: 3rd February 2006, 19:23

Tags for this Thread

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.