Results 1 to 7 of 7

Thread: UI string is too long for MSVC

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,540
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: UI string is too long for MSVC

    Put the text to file in resources not in C++ code. Additional profit: you can edit the text in the HTML editor.

  2. #2
    Join Date
    Oct 2009
    Location
    Craiova, Romania
    Posts
    46
    Thanks
    3
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: UI string is too long for MSVC

    Quote Originally Posted by Lesiok View Post
    Put the text to file in resources not in C++ code. Additional profit: you can edit the text in the HTML editor.
    Thank you! I don't really want to translate this large field, but I want all the strings in the application to be passed through tr(). I'll search how can I tr() the text from the resource file.

    Could you details how to read the resource file? Store it as XML UTF-8, or as text? Read it line by line?

  3. #3
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,540
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: UI string is too long for MSVC

    Something like this, if file name is thanks.txt (txt in UTF-8) and is located in main directory of resource file :
    Qt Code:
    1. QFile file(":/Resources/thanks.txt");
    2. file.open(QIODevice::ReadOnly);
    3. QByteArray my_txt = file.readAll();
    4. file.close();
    5. thanksToTextBrowser->setHtml(QApplication::translate(my_txt.constData()));
    To copy to clipboard, switch view to plain text mode 

    Of course I'm talking about Qt resources.

  4. The following user says thank you to Lesiok for this useful post:

    lalesculiviu (9th March 2018)

  5. #4
    Join Date
    Oct 2009
    Location
    Craiova, Romania
    Posts
    46
    Thanks
    3
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: UI string is too long for MSVC

    Thank you! I learned some nice Qt code with this. But I think that lupdate will not extract the thanks.txt string correctly.

  6. #5
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,540
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: UI string is too long for MSVC

    I do not think that adding such large text to QApplication::translate was a good idea. In my opinion, you should prepare separate txt files with the translated text and load the appropriate file.

  7. #6
    Join Date
    Oct 2009
    Location
    Craiova, Romania
    Posts
    46
    Thanks
    3
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: UI string is too long for MSVC

    I'll think about it. Thank you!

    But maybe Qt code should care about these long strings for MSVC.

    Note: I did not use directly the QApplication::translate. The file .\tmp\gui\ui_helpaboutform_template.h is generated automatically by Qt UIC, I only modify the file src/interface/helpaboutform_template.ui.

Similar Threads

  1. getting a string value back from long converted format
    By prachi kamble in forum General Programming
    Replies: 0
    Last Post: 1st February 2016, 07:05
  2. Replies: 2
    Last Post: 7th November 2015, 09:49
  3. Replies: 1
    Last Post: 21st September 2010, 08:58
  4. Problem with compiling Qt 4.6 via MSVC 2010 Beta2 (win32-msvc specs)
    By Erik-Moscow in forum Installation and Deployment
    Replies: 2
    Last Post: 17th December 2009, 18:44
  5. Qlabel size string too long
    By Pharell in forum Qt Programming
    Replies: 1
    Last Post: 10th June 2008, 15:20

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
  •  
Qt is a trademark of The Qt Company.