uic: Add -no-stringliteral option
... and use it when building shared libraries and plugins. It prevents application crashes in cases when libraries and plugins are unloaded and their strings are still used by the main application. Task-number: QTBUG-51602 Change-Id: I4af79183f18c5ed6142d55af02a36fe4334f3fee Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
This commit is contained in:
parent
8ba373361d
commit
d12d2949d1
@ -3,8 +3,10 @@ qtPrepareTool(QMAKE_UIC, uic, _DEP)
|
||||
isEmpty(UI_DIR):UI_DIR = .
|
||||
isEmpty(QMAKE_MOD_UIC):QMAKE_MOD_UIC = ui_
|
||||
|
||||
contains(TEMPLATE, .*lib):dll: QMAKE_UIC_FLAGS += -no-stringliteral
|
||||
|
||||
uic.depends += $$QMAKE_UIC_EXE
|
||||
uic.commands = $$QMAKE_UIC ${QMAKE_FILE_IN} -o ${QMAKE_FILE_OUT}
|
||||
uic.commands = $$QMAKE_UIC $$QMAKE_UIC_FLAGS ${QMAKE_FILE_IN} -o ${QMAKE_FILE_OUT}
|
||||
uic.depend_command = $$QMAKE_UIC_DEP -d ${QMAKE_FILE_IN}
|
||||
uic.output = $$UI_DIR/$${QMAKE_MOD_UIC}${QMAKE_FILE_BASE}$${first(QMAKE_EXT_H)}
|
||||
uic.input = FORMS
|
||||
|
@ -2266,6 +2266,14 @@
|
||||
|
||||
For more information, see \l {Expressing Supported iOS Versions}.
|
||||
|
||||
\section1 QMAKE_UIC_FLAGS
|
||||
|
||||
This variable is used to customize the list of options passed to the
|
||||
\l{uic}{User Interface Compiler} in each of the build rules where it is
|
||||
used. For example, \c{-no-stringliteral} can be passed to use QLatin1String
|
||||
instead of QStringLiteral in generated code (which is the default for
|
||||
dynamic libraries).
|
||||
|
||||
\section1 QMAKE_WATCHOS_DEPLOYMENT_TARGET
|
||||
|
||||
\note This variable is used on the watchOS platform only.
|
||||
|
@ -475,6 +475,21 @@ WriteInitialization::WriteInitialization(Uic *uic) :
|
||||
{
|
||||
}
|
||||
|
||||
QString WriteInitialization::writeString(const QString &s, const QString &indent) const
|
||||
{
|
||||
unsigned flags = 0;
|
||||
const QString ret = fixString(s, indent, &flags);
|
||||
if (flags & Utf8String)
|
||||
return QLatin1String("QString::fromUtf8(") + ret + QLatin1Char(')');
|
||||
// MSVC cannot concat L"foo" "bar" (C2308: concatenating mismatched strings),
|
||||
// use QLatin1String instead (all platforms to avoid cross-compiling issues).
|
||||
if (flags & MultiLineString)
|
||||
return QLatin1String("QLatin1String(") + ret + QLatin1Char(')');
|
||||
const QLatin1String stringWrapper = m_uic->option().stringLiteral ?
|
||||
QLatin1String("QStringLiteral(") : QLatin1String("QLatin1String(");
|
||||
return stringWrapper + ret + QLatin1Char(')');
|
||||
}
|
||||
|
||||
void WriteInitialization::acceptUI(DomUI *node)
|
||||
{
|
||||
m_actionGroupChain.push(0);
|
||||
@ -1601,10 +1616,10 @@ QString WriteInitialization::writeFontProperties(const DomFont *f)
|
||||
}
|
||||
|
||||
// Post 4.4 write resource icon
|
||||
static void writeResourceIcon(QTextStream &output,
|
||||
const QString &iconName,
|
||||
const QString &indent,
|
||||
const DomResourceIcon *i)
|
||||
void WriteInitialization::writeResourceIcon(QTextStream &output,
|
||||
const QString &iconName,
|
||||
const QString &indent,
|
||||
const DomResourceIcon *i) const
|
||||
{
|
||||
if (i->hasElementNormalOff())
|
||||
output << indent << iconName << ".addFile(" << writeString(i->elementNormalOff()->text(), indent) << ", QSize(), QIcon::Normal, QIcon::Off);\n";
|
||||
|
@ -139,6 +139,8 @@ struct WriteInitialization : public TreeWalker
|
||||
private:
|
||||
static QString domColor2QString(const DomColor *c);
|
||||
|
||||
QString writeString(const QString &s, const QString &indent) const;
|
||||
|
||||
QString iconCall(const DomProperty *prop);
|
||||
QString pixCall(const DomProperty *prop) const;
|
||||
QString pixCall(const QString &type, const QString &text) const;
|
||||
@ -228,6 +230,7 @@ private:
|
||||
|
||||
private:
|
||||
QString writeFontProperties(const DomFont *f);
|
||||
void writeResourceIcon(QTextStream &output, const QString &iconName, const QString &indent, const DomResourceIcon *i) const;
|
||||
QString writeIconProperties(const DomResourceIcon *i);
|
||||
QString writeSizePolicy(const DomSizePolicy *sp);
|
||||
QString writeBrushInitialization(const DomBrush *brush);
|
||||
|
@ -75,6 +75,10 @@ int runUic(int argc, char *argv[])
|
||||
noImplicitIncludesOption.setDescription(QStringLiteral("Disable generation of #include-directives."));
|
||||
parser.addOption(noImplicitIncludesOption);
|
||||
|
||||
QCommandLineOption noStringLiteralOption(QStringList() << QStringLiteral("s") << QStringLiteral("no-stringliteral"));
|
||||
noStringLiteralOption.setDescription(QStringLiteral("Use QLatin1String instead of QStringLiteral in generated code."));
|
||||
parser.addOption(noStringLiteralOption);
|
||||
|
||||
QCommandLineOption postfixOption(QStringLiteral("postfix"));
|
||||
postfixOption.setDescription(QStringLiteral("Postfix to add to all generated classnames."));
|
||||
postfixOption.setValueName(QStringLiteral("postfix"));
|
||||
@ -107,6 +111,7 @@ int runUic(int argc, char *argv[])
|
||||
driver.option().outputFile = parser.value(outputOption);
|
||||
driver.option().headerProtection = !parser.isSet(noProtOption);
|
||||
driver.option().implicitIncludes = !parser.isSet(noImplicitIncludesOption);
|
||||
driver.option().stringLiteral = !parser.isSet(noStringLiteralOption);
|
||||
driver.option().idBased = parser.isSet(idBasedOption);
|
||||
driver.option().postfix = parser.value(postfixOption);
|
||||
driver.option().translateFunction = parser.value(translateOption);
|
||||
|
@ -51,6 +51,7 @@ struct Option
|
||||
unsigned int limitXPM_LineLength : 1;
|
||||
unsigned int implicitIncludes: 1;
|
||||
unsigned int idBased: 1;
|
||||
unsigned int stringLiteral: 1;
|
||||
Generator generator;
|
||||
|
||||
QString inputFile;
|
||||
@ -76,6 +77,7 @@ struct Option
|
||||
limitXPM_LineLength(0),
|
||||
implicitIncludes(1),
|
||||
idBased(0),
|
||||
stringLiteral(1),
|
||||
generator(CppGenerator),
|
||||
prefix(QLatin1String("Ui_"))
|
||||
{ indent.fill(QLatin1Char(' '), 4); }
|
||||
|
@ -107,19 +107,6 @@ inline QString fixString(const QString &str, const QString &indent,
|
||||
return rc;
|
||||
}
|
||||
|
||||
inline QString writeString(const QString &s, const QString &indent)
|
||||
{
|
||||
unsigned flags = 0;
|
||||
const QString ret = fixString(s, indent, &flags);
|
||||
if (flags & Utf8String)
|
||||
return QLatin1String("QString::fromUtf8(") + ret + QLatin1Char(')');
|
||||
// MSVC cannot concat L"foo" "bar" (C2308: concatenating mismatched strings),
|
||||
// use QLatin1String instead (all platforms to avoid cross-compiling issues).
|
||||
if (flags & MultiLineString)
|
||||
return QLatin1String("QLatin1String(") + ret + QLatin1Char(')');
|
||||
return QLatin1String("QStringLiteral(") + ret + QLatin1Char(')');
|
||||
}
|
||||
|
||||
inline QHash<QString, DomProperty *> propertyMap(const QList<DomProperty *> &properties)
|
||||
{
|
||||
QHash<QString, DomProperty *> map;
|
||||
|
Loading…
Reference in New Issue
Block a user