Results 1 to 7 of 7

Thread: UI string is too long for MSVC

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

    Default UI string is too long for MSVC

    Dear Qt Centre community,

    I am the author of free software named FET (https://lalescu.ro/liviu/fet/download.html).

    It compiles well under gcc or MinGW with the latest Qt 5.10.1, on Windows, GNU/Linux or Mac OS X (I think under Max OS X the users compile it with clang).

    Unfortunately, it does not compile on MSVC (Microsoft Visual Studio).

    There is a file, fet-v.v.v/src/interface/helpaboutform_template.ui, which is very large, contains one very large string in Unicode UTF-8, in a QTextBrowser.

    MSVC gives this error:

    .\tmp\gui\ui_helpaboutform_template.h:884: Fehler: C1091: Compilerlimit : Die Zeichenfolge berschreitet die L„nge um 65535 Bytes

    That means: Compiler limit reached because of too many characters.

    The string is written in .\tmp\gui\ui_helpaboutform_template.h beginning as:

    Qt Code:
    1. thanksToTextBrowser->setHtml(QApplication::translate("HelpAboutForm_template", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
    2. "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
    3. "p, li { white-space: pre-wrap; }\n"
    4. "</style></head><body style=\" font-family:'Sans'; font-size:10pt; font-weight:400; font-style:normal;\">\n"
    5. "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:9pt;\">(chronologically):</span></p>\n"
    6. "<p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:9pt;\"><br /></p>\n"
    7. "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:9pt;\">Costin Badica - he advised Liviu Lalescu to begin this project and offered many suggestions.</span></p>\n"
    8. "<p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0p"
    9. "x; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:9pt;\"><br /></p>\n"
    10. "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:9pt;\">Carsten Niehaus - suggestions.</span></p>\n"
    To copy to clipboard, switch view to plain text mode 

    I could solve this by writing the text into more C++ strings, but the characters are UTF-8 (Unicode) and I don't want to add special characters into the C++ sources.

    How could I solve this problem?

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    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.

  3. #3
    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?

  4. #4
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    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.

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

    lalesculiviu (9th March 2018)

  6. #5
    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.

  7. #6
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    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.

  8. #7
    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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.