QString: mark obsolete functions as deprecated

Mark obsolete functions in QString as deprecated so they can be removed
with Qt6:
 - QString::sprintf()
 - QString::vsprintf()

Change-Id: I9b7748db95291c34b95ff3ad3e3aabc8215aeaae
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@qt.io>
This commit is contained in:
Christian Ehrlicher 2019-02-18 21:53:22 +01:00
parent 7a7ec94d6c
commit f8f592d5c2
7 changed files with 37 additions and 37 deletions

View File

@ -882,8 +882,7 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinExpand(
ret += values(map(args.at(0)));
break;
case E_LIST: {
QString tmp;
tmp.sprintf(".QMAKE_INTERNAL_TMP_variableName_%d", m_listCount++);
QString tmp(QString::asprintf(".QMAKE_INTERNAL_TMP_variableName_%d", m_listCount++));
ret = ProStringList(ProString(tmp));
ProStringList lst;
for (const ProString &arg : args)

View File

@ -6835,6 +6835,7 @@ QString QString::toUpper_helper(QString &str)
return QUnicodeTables::convertCase<QUnicodeTables::UppercaseTraits>(str);
}
#if QT_DEPRECATED_SINCE(5, 14)
/*!
\obsolete
@ -6848,6 +6849,7 @@ QString &QString::sprintf(const char *cformat, ...)
va_end(ap);
return *this;
}
#endif
// ### Qt 6: Consider whether this function shouldn't be removed See task 202871.
/*!
@ -6893,6 +6895,7 @@ QString QString::asprintf(const char *cformat, ...)
return s;
}
#if QT_DEPRECATED_SINCE(5, 14)
/*!
\obsolete
@ -6902,6 +6905,7 @@ QString &QString::vsprintf(const char *cformat, va_list ap)
{
return *this = vasprintf(cformat, ap);
}
#endif
static void append_utf8(QString &qs, const char *cs, int len)
{

View File

@ -320,8 +320,12 @@ public:
const QString &a4, const QString &a5, const QString &a6,
const QString &a7, const QString &a8, const QString &a9) const;
#if QT_DEPRECATED_SINCE(5, 14)
QT_DEPRECATED_X("Use vasprintf(), arg() or QTextStream instead")
QString &vsprintf(const char *format, va_list ap) Q_ATTRIBUTE_FORMAT_PRINTF(2, 0);
QT_DEPRECATED_X("Use asprintf(), arg() or QTextStream instead")
QString &sprintf(const char *format, ...) Q_ATTRIBUTE_FORMAT_PRINTF(2, 3);
#endif
static QString vasprintf(const char *format, va_list ap) Q_ATTRIBUTE_FORMAT_PRINTF(1, 0);
static QString asprintf(const char *format, ...) Q_ATTRIBUTE_FORMAT_PRINTF(1, 2);

View File

@ -1671,19 +1671,19 @@ int QPdfEnginePrivate::writeXmpMetaData()
const QDateTime now = QDateTime::currentDateTime();
const QDate date = now.date();
const QTime time = now.time();
QString timeStr;
timeStr.sprintf("%d-%02d-%02dT%02d:%02d:%02d", date.year(), date.month(), date.day(),
time.hour(), time.minute(), time.second());
const QString timeStr =
QString::asprintf("%d-%02d-%02dT%02d:%02d:%02d",
date.year(), date.month(), date.day(),
time.hour(), time.minute(), time.second());
const int offset = now.offsetFromUtc();
const int hours = (offset / 60) / 60;
const int mins = (offset / 60) % 60;
QString tzStr;
if (offset < 0)
tzStr.sprintf("-%02d:%02d", -hours, -mins);
tzStr = QString::asprintf("-%02d:%02d", -hours, -mins);
else if (offset > 0)
tzStr.sprintf("+%02d:%02d", hours , mins);
tzStr = QString::asprintf("+%02d:%02d", hours , mins);
else
tzStr = QLatin1String("Z");

View File

@ -777,9 +777,7 @@ void QKmsDevice::discoverPlanes()
for (int i = 0; i < countFormats; ++i) {
uint32_t f = drmplane->formats[i];
plane.supportedFormats.append(f);
QString s;
s.sprintf("%c%c%c%c ", f, f >> 8, f >> 16, f >> 24);
formatStr += s;
formatStr += QString::asprintf("%c%c%c%c ", f, f >> 8, f >> 16, f >> 24);
}
qCDebug(qLcKmsDebug, "plane %d: id = %u countFormats = %d possibleCrtcs = 0x%x supported formats = %s",

View File

@ -495,7 +495,7 @@ void QPrintPreviewDialogPrivate::updatePageNumLabel()
void QPrintPreviewDialogPrivate::updateZoomFactor()
{
zoomFactor->lineEdit()->setText(QString().sprintf("%.1f%%", preview->zoomFactor()*100));
zoomFactor->lineEdit()->setText(QString::asprintf("%.1f%%", preview->zoomFactor()*100));
}
void QPrintPreviewDialogPrivate::_q_fit(QAction* action)

View File

@ -192,22 +192,20 @@ QString VkSpecParser::parseName()
QString funcSig(const VkSpecParser::Command &c, const char *className = nullptr)
{
QString s;
s.sprintf("%s %s%s%s", qPrintable(c.cmd.type),
(className ? className : ""), (className ? "::" : ""),
qPrintable(c.cmd.name));
QString s(QString::asprintf("%s %s%s%s", qPrintable(c.cmd.type),
(className ? className : ""), (className ? "::" : ""),
qPrintable(c.cmd.name)));
if (!c.args.isEmpty()) {
s += QLatin1Char('(');
bool first = true;
for (const VkSpecParser::TypedName &a : c.args) {
QString argStr;
argStr.sprintf("%s%s%s%s", qPrintable(a.type), (a.type.endsWith(QLatin1Char('*')) ? "" : " "),
qPrintable(a.name), qPrintable(a.typeSuffix));
if (!first)
s += QStringLiteral(", ");
else
first = false;
s += argStr;
s += QString::asprintf("%s%s%s%s", qPrintable(a.type),
(a.type.endsWith(QLatin1Char('*')) ? "" : " "),
qPrintable(a.name), qPrintable(a.typeSuffix));
}
s += QLatin1Char(')');
}
@ -216,13 +214,12 @@ QString funcSig(const VkSpecParser::Command &c, const char *className = nullptr)
QString funcCall(const VkSpecParser::Command &c, int idx)
{
QString s;
// template:
// [return] reinterpret_cast<PFN_vkEnumeratePhysicalDevices>(d_ptr->m_funcs[0])(instance, pPhysicalDeviceCount, pPhysicalDevices);
s.sprintf("%sreinterpret_cast<PFN_%s>(d_ptr->m_funcs[%d])",
(c.cmd.type == QStringLiteral("void") ? "" : "return "),
qPrintable(c.cmd.name),
idx);
QString s = QString::asprintf("%sreinterpret_cast<PFN_%s>(d_ptr->m_funcs[%d])",
(c.cmd.type == QStringLiteral("void") ? "" : "return "),
qPrintable(c.cmd.name),
idx);
if (!c.args.isEmpty()) {
s += QLatin1Char('(');
bool first = true;
@ -338,10 +335,9 @@ bool genVulkanFunctionsH(const QVector<VkSpecParser::Command> &commands, const Q
*dst += QStringLiteral(";\n");
}
QString str;
str.sprintf(s, preamble.get(licHeaderFn).constData(), instCmdStr.toUtf8().constData(), devCmdStr.toUtf8().constData());
f.write(str.toUtf8());
f.write(QString::asprintf(s, preamble.get(licHeaderFn).constData(),
instCmdStr.toUtf8().constData(),
devCmdStr.toUtf8().constData()).toUtf8());
return true;
}
@ -400,10 +396,7 @@ bool genVulkanFunctionsPH(const QVector<VkSpecParser::Command> &commands, const
[](const VkSpecParser::Command &c) { return c.deviceLevel; });
const int instLevelCount = commands.count() - devLevelCount;
QString str;
str.sprintf(s, preamble.get(licHeaderFn).constData(), instLevelCount, devLevelCount);
f.write(str.toUtf8());
f.write(QString::asprintf(s, preamble.get(licHeaderFn).constData(), instLevelCount, devLevelCount).toUtf8());
return true;
}
@ -478,10 +471,12 @@ bool genVulkanFunctionsPC(const QVector<VkSpecParser::Command> &commands, const
if (instCmdNamesStr.count() > 2)
instCmdNamesStr = instCmdNamesStr.left(instCmdNamesStr.count() - 2);
QString str;
str.sprintf(s, preamble.get(licHeaderFn).constData(),
instCmdWrapperStr.toUtf8().constData(), instCmdNamesStr.toUtf8().constData(), instIdx,
devCmdWrapperStr.toUtf8().constData(), devCmdNamesStr.toUtf8().constData(), commands.count() - instIdx);
const QString str =
QString::asprintf(s, preamble.get(licHeaderFn).constData(),
instCmdWrapperStr.toUtf8().constData(),
instCmdNamesStr.toUtf8().constData(), instIdx,
devCmdWrapperStr.toUtf8().constData(),
devCmdNamesStr.toUtf8().constData(), commands.count() - instIdx);
f.write(str.toUtf8());