PDA

View Full Version : UI string is too long for MSVC



lalesculiviu
9th March 2018, 12:00
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:


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"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:'Sans'; font-size:10pt; font-weight:400; font-style:normal;\">\n"
"<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"
"<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"
"<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"
"<p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0p"
"x; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:9pt;\"><br /></p>\n"
"<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"


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?

Lesiok
9th March 2018, 14:30
Put the text to file in resources not in C++ code. Additional profit: you can edit the text in the HTML editor.

lalesculiviu
9th March 2018, 14:59
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?

Lesiok
9th March 2018, 16:51
Something like this, if file name is thanks.txt (txt in UTF-8) and is located in main directory of resource file :

QFile file(":/Resources/thanks.txt");
file.open(QIODevice::ReadOnly);
QByteArray my_txt = file.readAll();
file.close();
thanksToTextBrowser->setHtml(QApplication::translate(my_txt.constData() ));

Of course I'm talking about Qt resources (http://doc.qt.io/qt-5/resources.html).

lalesculiviu
9th March 2018, 17:28
Thank you! I learned some nice Qt code with this. But I think that lupdate will not extract the thanks.txt string correctly.

Lesiok
10th March 2018, 09:01
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.

lalesculiviu
10th March 2018, 09:20
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.