From df853fed66d891077ae2d04ecfa171d7e2cd5202 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Fri, 19 Jun 2020 20:53:25 +0200 Subject: Use qsizetype in QList The change creates a slight source incompatibility. The main things to take care of are * code using printf statements on list.size(). Using qsizetype in printf statements will always require a cast to work on both 32 and 64 bit. * A few places where overloads now get ambiguous. One example is QRandomGenerator::bounded() that has overloads for int, uint and double, but not int64. * Streaming list.size() to a QDataStream will change the format depending on the architecture. [ChangeLog][QtCore][QList] QList now uses qsizetype to index into elements. Change-Id: Iaff562a4d072b97f458417b670f95971bd47cbc6 Reviewed-by: Thiago Macieira --- examples/embedded/flickable/main.cpp | 2 +- examples/network/fortuneserver/server.cpp | 2 +- .../threadedfortuneserver/fortuneserver.cpp | 2 +- examples/network/torrent/torrentclient.cpp | 16 +-- .../widgets/mainwindows/mainwindow/toolbar.cpp | 2 +- qmake/generators/xmloutput.cpp | 2 +- src/corelib/kernel/qmetaobjectbuilder.cpp | 4 +- src/corelib/serialization/qjsonobject.cpp | 2 +- src/corelib/text/qstringlist.cpp | 56 +++++----- src/corelib/text/qstringlist.h | 38 +++---- src/corelib/tools/qlist.h | 124 ++++++++++----------- src/gui/itemmodels/qstandarditemmodel.cpp | 2 +- src/gui/painting/qpdf_p.h | 1 + src/gui/rhi/qrhivulkan.cpp | 2 +- src/gui/text/qtextdocument_p.cpp | 2 +- src/gui/text/qtextlayout.cpp | 2 +- src/gui/text/qtextmarkdownimporter.cpp | 10 +- src/network/kernel/qdnslookup.cpp | 2 +- src/opengl/qopenglshaderprogram.cpp | 2 +- src/platformsupport/kmsconvenience/qkmsdevice.cpp | 2 +- .../platforms/android/qandroidinputcontext.cpp | 4 +- src/tools/moc/generator.cpp | 24 ++-- src/widgets/itemviews/qheaderview.cpp | 2 +- src/widgets/itemviews/qtreeview.cpp | 2 +- src/widgets/widgets/qdatetimeedit.cpp | 4 +- src/widgets/widgets/qdockarealayout.cpp | 2 +- src/widgets/widgets/qtoolbararealayout.cpp | 2 +- .../serialization/qcborvalue/tst_qcborvalue.cpp | 4 +- tests/auto/gui/painting/qregion/tst_qregion.cpp | 2 +- .../access/qnetworkreply/tst_qnetworkreply.cpp | 4 +- .../qdialogbuttonbox/tst_qdialogbuttonbox.cpp | 24 ++-- .../widgets/widgets/qgroupbox/tst_qgroupbox.cpp | 2 +- tests/auto/widgets/widgets/qtabbar/tst_qtabbar.cpp | 4 +- 33 files changed, 178 insertions(+), 177 deletions(-) diff --git a/examples/embedded/flickable/main.cpp b/examples/embedded/flickable/main.cpp index 973154331d..d3b314fcd0 100644 --- a/examples/embedded/flickable/main.cpp +++ b/examples/embedded/flickable/main.cpp @@ -72,7 +72,7 @@ static QStringList colorPairs(int max) // randomize it colors.clear(); while (combinedColors.count()) { - int i = QRandomGenerator::global()->bounded(combinedColors.count()); + int i = QRandomGenerator::global()->bounded(int(combinedColors.count())); colors << combinedColors[i]; combinedColors.removeAt(i); if (colors.count() == max) diff --git a/examples/network/fortuneserver/server.cpp b/examples/network/fortuneserver/server.cpp index c91b6a5c0c..95aadb60c9 100644 --- a/examples/network/fortuneserver/server.cpp +++ b/examples/network/fortuneserver/server.cpp @@ -145,7 +145,7 @@ void Server::sendFortune() QDataStream out(&block, QIODevice::WriteOnly); out.setVersion(QDataStream::Qt_5_10); - out << fortunes[QRandomGenerator::global()->bounded(fortunes.size())]; + out << fortunes[QRandomGenerator::global()->bounded(int(fortunes.size()))]; //! [4] //! [7] QTcpSocket *clientConnection = tcpServer->nextPendingConnection(); diff --git a/examples/network/threadedfortuneserver/fortuneserver.cpp b/examples/network/threadedfortuneserver/fortuneserver.cpp index 73d7e22531..a93bbc7058 100644 --- a/examples/network/threadedfortuneserver/fortuneserver.cpp +++ b/examples/network/threadedfortuneserver/fortuneserver.cpp @@ -72,7 +72,7 @@ FortuneServer::FortuneServer(QObject *parent) //! [1] void FortuneServer::incomingConnection(qintptr socketDescriptor) { - QString fortune = fortunes.at(QRandomGenerator::global()->bounded(fortunes.size())); + QString fortune = fortunes.at(QRandomGenerator::global()->bounded(int(fortunes.size()))); FortuneThread *thread = new FortuneThread(socketDescriptor, fortune, this); connect(thread, &FortuneThread::finished, thread, &FortuneThread::deleteLater); thread->start(); diff --git a/examples/network/torrent/torrentclient.cpp b/examples/network/torrent/torrentclient.cpp index 035cf665bb..6ae5339d28 100644 --- a/examples/network/torrent/torrentclient.cpp +++ b/examples/network/torrent/torrentclient.cpp @@ -700,7 +700,7 @@ void TorrentClient::connectToPeers() d->connections << client; // Pick a random peer from the list of weighed peers. - TorrentPeer *peer = weighedPeers.takeAt(QRandomGenerator::global()->bounded(weighedPeers.size())); + TorrentPeer *peer = weighedPeers.takeAt(QRandomGenerator::global()->bounded(int(weighedPeers.size()))); weighedPeers.removeAll(peer); peer->connectStart = QDateTime::currentSecsSinceEpoch(); peer->lastVisited = peer->connectStart; @@ -1130,7 +1130,7 @@ void TorrentClient::scheduleUploads() // random peer to allow it to compete for a position among the // downloaders. (This is known as an "optimistic unchoke".) if (!allClients.isEmpty()) { - PeerWireClient *client = allClients[QRandomGenerator::global()->bounded(allClients.size())]; + PeerWireClient *client = allClients[QRandomGenerator::global()->bounded(int(allClients.size()))]; if (client->peerWireState() & PeerWireClient::ChokingPeer) client->unchokePeer(); } @@ -1191,7 +1191,7 @@ void TorrentClient::schedulePieceForClient(PeerWireClient *client) piece = d->payloads.value(client); if (!piece) { QList values = d->pendingPieces.values(); - piece = values.value(QRandomGenerator::global()->bounded(values.size())); + piece = values.value(QRandomGenerator::global()->bounded(int(values.size()))); piece->inProgress = true; d->payloads.insert(client, piece); } @@ -1248,7 +1248,7 @@ void TorrentClient::schedulePieceForClient(PeerWireClient *client) ++it; } if (!partialPieces.isEmpty()) - piece = partialPieces.value(QRandomGenerator::global()->bounded(partialPieces.size())); + piece = partialPieces.value(QRandomGenerator::global()->bounded(int(partialPieces.size()))); if (!piece) { // Pick a random piece 3 out of 4 times; otherwise, pick either @@ -1295,7 +1295,7 @@ void TorrentClient::schedulePieceForClient(PeerWireClient *client) } // Select one piece randomly - pieceIndex = piecesReadyForDownload.at(QRandomGenerator::global()->bounded(piecesReadyForDownload.size())); + pieceIndex = piecesReadyForDownload.at(QRandomGenerator::global()->bounded(int(piecesReadyForDownload.size()))); delete [] occurrences; } else { // Make up a list of available piece indices, and pick @@ -1306,7 +1306,7 @@ void TorrentClient::schedulePieceForClient(PeerWireClient *client) if (incompletePiecesAvailableToClient.testBit(i)) values << i; } - pieceIndex = values.at(QRandomGenerator::global()->bounded(values.size())); + pieceIndex = values.at(QRandomGenerator::global()->bounded(int(values.size()))); } // Create a new TorrentPiece and fill in all initial @@ -1398,8 +1398,8 @@ int TorrentClient::requestBlocks(PeerWireClient *client, TorrentPiece *piece, in // speedup comes from an increased chance of receiving // different blocks from the different peers. for (int i = 0; i < bits.size(); ++i) { - int a = QRandomGenerator::global()->bounded(bits.size()); - int b = QRandomGenerator::global()->bounded(bits.size()); + int a = QRandomGenerator::global()->bounded(int(bits.size())); + int b = QRandomGenerator::global()->bounded(int(bits.size())); int tmp = bits[a]; bits[a] = bits[b]; bits[b] = tmp; diff --git a/examples/widgets/mainwindows/mainwindow/toolbar.cpp b/examples/widgets/mainwindows/mainwindow/toolbar.cpp index 6a5faf248f..fd510c8a57 100644 --- a/examples/widgets/mainwindows/mainwindow/toolbar.cpp +++ b/examples/widgets/mainwindows/mainwindow/toolbar.cpp @@ -264,7 +264,7 @@ void ToolBar::randomize() QList randomized; QList actions = this->actions(); while (!actions.isEmpty()) { - QAction *action = actions.takeAt(QRandomGenerator::global()->bounded(actions.size())); + QAction *action = actions.takeAt(QRandomGenerator::global()->bounded(int(actions.size()))); randomized.append(action); } clear(); diff --git a/qmake/generators/xmloutput.cpp b/qmake/generators/xmloutput.cpp index 7fc1b081c7..c43f8d810b 100644 --- a/qmake/generators/xmloutput.cpp +++ b/qmake/generators/xmloutput.cpp @@ -267,7 +267,7 @@ void XmlOutput::closeTag() case Bare: if (tagStack.count()) //warn_msg(WarnLogic, ": Cannot close tag in Bare state, %d tags on stack", tagStack.count()); - qDebug(": Cannot close tag in Bare state, %d tags on stack", tagStack.count()); + qDebug(": Cannot close tag in Bare state, %d tags on stack", int(tagStack.count())); else //warn_msg(WarnLogic, ": Cannot close tag, no tags on stack"); qDebug(": Cannot close tag, no tags on stack"); diff --git a/src/corelib/kernel/qmetaobjectbuilder.cpp b/src/corelib/kernel/qmetaobjectbuilder.cpp index b418cd2dab..ba8d92de7d 100644 --- a/src/corelib/kernel/qmetaobjectbuilder.cpp +++ b/src/corelib/kernel/qmetaobjectbuilder.cpp @@ -1598,12 +1598,12 @@ void QMetaObjectBuilder::serialize(QDataStream& stream) const stream << QByteArray(); // Write the counts for each type of class member. - stream << d->classInfoNames.size(); + stream << int(d->classInfoNames.size()); stream << int(d->methods.size()); stream << int(d->properties.size()); stream << int(d->enumerators.size()); stream << int(d->constructors.size()); - stream << d->relatedMetaObjects.size(); + stream << int(d->relatedMetaObjects.size()); // Write the items of class information. for (index = 0; index < d->classInfoNames.size(); ++index) { diff --git a/src/corelib/serialization/qjsonobject.cpp b/src/corelib/serialization/qjsonobject.cpp index bf2bdb957d..e573485226 100644 --- a/src/corelib/serialization/qjsonobject.cpp +++ b/src/corelib/serialization/qjsonobject.cpp @@ -718,7 +718,7 @@ bool QJsonObject::operator!=(const QJsonObject &other) const QJsonObject::iterator QJsonObject::erase(QJsonObject::iterator it) { if (it.o != this || it.i < 0 || it.i >= o->elements.length()) - return {this, o->elements.length()}; + return {this, int(o->elements.length())}; int index = it.i; diff --git a/src/corelib/text/qstringlist.cpp b/src/corelib/text/qstringlist.cpp index 942b1fdf97..6d5228ce6b 100644 --- a/src/corelib/text/qstringlist.cpp +++ b/src/corelib/text/qstringlist.cpp @@ -314,7 +314,7 @@ QStringList QtPrivate::QStringList_filter(const QStringList *that, QStringView s { QStringMatcher matcher(str, cs); QStringList res; - for (int i = 0; i < that->size(); ++i) + for (qsizetype i = 0; i < that->size(); ++i) if (matcher.indexIn(that->at(i)) != -1) res << that->at(i); return res; @@ -327,7 +327,7 @@ QStringList QtPrivate::QStringList_filter(const QStringList *that, const QString { QStringMatcher matcher(str, cs); QStringList res; - for (int i = 0; i < that->size(); ++i) + for (qsizetype i = 0; i < that->size(); ++i) if (matcher.indexIn(that->at(i)) != -1) res << that->at(i); return res; @@ -399,7 +399,7 @@ bool QtPrivate::QStringList_contains(const QStringList *that, QLatin1String str, } /*! - \fn bool QStringList::indexOf(QStringView str, int from) const + \fn bool QStringList::indexOf(QStringView str, qsizetype from) const \overload \since 5.13 @@ -411,7 +411,7 @@ bool QtPrivate::QStringList_contains(const QStringList *that, QLatin1String str, */ /*! - \fn bool QStringList::indexOf(QLatin1String str, int from) const + \fn bool QStringList::indexOf(QLatin1String str, qsizetype from) const \overload \since 5.13 @@ -423,7 +423,7 @@ bool QtPrivate::QStringList_contains(const QStringList *that, QLatin1String str, */ /*! - \fn bool QStringList::lastIndexOf(QStringView str, int from) const + \fn bool QStringList::lastIndexOf(QStringView str, qsizetype from) const \overload \since 5.13 @@ -436,7 +436,7 @@ bool QtPrivate::QStringList_contains(const QStringList *that, QLatin1String str, */ /*! - \fn bool QStringList::lastIndexOf(QLatin1String str, int from) const + \fn bool QStringList::lastIndexOf(QLatin1String str, qsizetype from) const \overload \since 5.13 @@ -460,7 +460,7 @@ bool QtPrivate::QStringList_contains(const QStringList *that, QLatin1String str, QStringList QtPrivate::QStringList_filter(const QStringList *that, const QRegularExpression &re) { QStringList res; - for (int i = 0; i < that->size(); ++i) { + for (qsizetype i = 0; i < that->size(); ++i) { if (that->at(i).contains(re)) res << that->at(i); } @@ -506,7 +506,7 @@ QStringList QtPrivate::QStringList_filter(const QStringList *that, const QRegula void QtPrivate::QStringList_replaceInStrings(QStringList *that, QStringView before, QStringView after, Qt::CaseSensitivity cs) { - for (int i = 0; i < that->size(); ++i) + for (qsizetype i = 0; i < that->size(); ++i) (*that)[i].replace(before.data(), before.length(), after.data(), after.length(), cs); } @@ -515,7 +515,7 @@ void QtPrivate::QStringList_replaceInStrings(QStringList *that, QStringView befo void QtPrivate::QStringList_replaceInStrings(QStringList *that, const QString &before, const QString &after, Qt::CaseSensitivity cs) { - for (int i = 0; i < that->size(); ++i) + for (qsizetype i = 0; i < that->size(); ++i) (*that)[i].replace(before, after, cs); } #endif @@ -546,14 +546,14 @@ void QtPrivate::QStringList_replaceInStrings(QStringList *that, const QString &b */ void QtPrivate::QStringList_replaceInStrings(QStringList *that, const QRegularExpression &re, const QString &after) { - for (int i = 0; i < that->size(); ++i) + for (qsizetype i = 0; i < that->size(); ++i) (*that)[i].replace(re, after); } #endif // QT_CONFIG(regularexpression) -static int accumulatedSize(const QStringList &list, int seplen) +static qsizetype accumulatedSize(const QStringList &list, qsizetype seplen) { - int result = 0; + qsizetype result = 0; if (!list.isEmpty()) { for (const auto &e : list) result += e.size() + seplen; @@ -579,16 +579,16 @@ static int accumulatedSize(const QStringList &list, int seplen) \since 5.0 \overload join() */ -QString QtPrivate::QStringList_join(const QStringList *that, const QChar *sep, int seplen) +QString QtPrivate::QStringList_join(const QStringList *that, const QChar *sep, qsizetype seplen) { - const int totalLength = accumulatedSize(*that, seplen); - const int size = that->size(); + const qsizetype totalLength = accumulatedSize(*that, seplen); + const qsizetype size = that->size(); QString res; if (totalLength == 0) return res; res.reserve(totalLength); - for (int i = 0; i < size; ++i) { + for (qsizetype i = 0; i < size; ++i) { if (i) res.append(sep, seplen); res += that->at(i); @@ -666,7 +666,7 @@ QString QtPrivate::QStringList_join(const QStringList *that, QStringView sep) #if QT_CONFIG(regularexpression) /*! - \fn int QStringList::indexOf(const QRegularExpression &re, int from) const + \fn qsizetype QStringList::indexOf(const QRegularExpression &re, qsizetype from) const \overload \since 5.0 @@ -676,15 +676,15 @@ QString QtPrivate::QStringList_join(const QStringList *that, QStringView sep) \sa lastIndexOf() */ -int QtPrivate::QStringList_indexOf(const QStringList *that, const QRegularExpression &re, int from) +qsizetype QtPrivate::QStringList_indexOf(const QStringList *that, const QRegularExpression &re, qsizetype from) { if (from < 0) - from = qMax(from + that->size(), 0); + from = qMax(from + that->size(), qsizetype(0)); QString exactPattern = QRegularExpression::anchoredPattern(re.pattern()); QRegularExpression exactRe(exactPattern, re.patternOptions()); - for (int i = from; i < that->size(); ++i) { + for (qsizetype i = from; i < that->size(); ++i) { QRegularExpressionMatch m = exactRe.match(that->at(i)); if (m.hasMatch()) return i; @@ -693,7 +693,7 @@ int QtPrivate::QStringList_indexOf(const QStringList *that, const QRegularExpres } /*! - \fn int QStringList::lastIndexOf(const QRegularExpression &re, int from) const + \fn qsizetype QStringList::lastIndexOf(const QRegularExpression &re, qsizetype from) const \overload \since 5.0 @@ -704,7 +704,7 @@ int QtPrivate::QStringList_indexOf(const QStringList *that, const QRegularExpres \sa indexOf() */ -int QtPrivate::QStringList_lastIndexOf(const QStringList *that, const QRegularExpression &re, int from) +qsizetype QtPrivate::QStringList_lastIndexOf(const QStringList *that, const QRegularExpression &re, qsizetype from) { if (from < 0) from += that->size(); @@ -714,7 +714,7 @@ int QtPrivate::QStringList_lastIndexOf(const QStringList *that, const QRegularEx QString exactPattern = QRegularExpression::anchoredPattern(re.pattern()); QRegularExpression exactRe(exactPattern, re.patternOptions()); - for (int i = from; i >= 0; --i) { + for (qsizetype i = from; i >= 0; --i) { QRegularExpressionMatch m = exactRe.match(that->at(i)); if (m.hasMatch()) return i; @@ -724,7 +724,7 @@ int QtPrivate::QStringList_lastIndexOf(const QStringList *that, const QRegularEx #endif // QT_CONFIG(regularexpression) /*! - \fn int QStringList::removeDuplicates() + \fn qsizetype QStringList::removeDuplicates() \since 4.5 @@ -734,14 +734,14 @@ int QtPrivate::QStringList_lastIndexOf(const QStringList *that, const QRegularEx Returns the number of removed entries. */ -int QtPrivate::QStringList_removeDuplicates(QStringList *that) +qsizetype QtPrivate::QStringList_removeDuplicates(QStringList *that) { - int n = that->size(); - int j = 0; + qsizetype n = that->size(); + qsizetype j = 0; QDuplicateTracker seen; seen.reserve(n); - for (int i = 0; i < n; ++i) { + for (qsizetype i = 0; i < n; ++i) { const QString &s = that->at(i); if (seen.hasSeen(s)) continue; diff --git a/src/corelib/text/qstringlist.h b/src/corelib/text/qstringlist.h index 9c4daedd4b..bee76ba67d 100644 --- a/src/corelib/text/qstringlist.h +++ b/src/corelib/text/qstringlist.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2020 The Qt Company Ltd. ** Copyright (C) 2016 Intel Corporation. ** Contact: https://www.qt.io/licensing/ ** @@ -71,7 +71,7 @@ protected: #endif public: inline void sort(Qt::CaseSensitivity cs = Qt::CaseSensitive); - inline int removeDuplicates(); + inline qsizetype removeDuplicates(); #if QT_STRINGVIEW_LEVEL < 2 inline QString join(const QString &sep) const; @@ -134,15 +134,15 @@ public: inline QStringList &operator<<(const QList &l) { *this += l; return *this; } - inline int indexOf(QStringView str, int from = 0) const; - inline int indexOf(QLatin1String str, int from = 0) const; + inline qsizetype indexOf(QStringView str, qsizetype from = 0) const; + inline qsizetype indexOf(QLatin1String str, qsizetype from = 0) const; - inline int lastIndexOf(QStringView str, int from = -1) const; - inline int lastIndexOf(QLatin1String str, int from = -1) const; + inline qsizetype lastIndexOf(QStringView str, qsizetype from = -1) const; + inline qsizetype lastIndexOf(QLatin1String str, qsizetype from = -1) const; #if QT_CONFIG(regularexpression) - inline int indexOf(const QRegularExpression &re, int from = 0) const; - inline int lastIndexOf(const QRegularExpression &re, int from = -1) const; + inline qsizetype indexOf(const QRegularExpression &re, qsizetype from = 0) const; + inline qsizetype lastIndexOf(const QRegularExpression &re, qsizetype from = -1) const; #endif // QT_CONFIG(regularexpression) using QList::indexOf; @@ -159,9 +159,9 @@ inline const QStringList *QListSpecialMethods::self() const namespace QtPrivate { void Q_CORE_EXPORT QStringList_sort(QStringList *that, Qt::CaseSensitivity cs); - int Q_CORE_EXPORT QStringList_removeDuplicates(QStringList *that); + qsizetype Q_CORE_EXPORT QStringList_removeDuplicates(QStringList *that); QString Q_CORE_EXPORT QStringList_join(const QStringList *that, QStringView sep); - QString Q_CORE_EXPORT QStringList_join(const QStringList *that, const QChar *sep, int seplen); + QString Q_CORE_EXPORT QStringList_join(const QStringList *that, const QChar *sep, qsizetype seplen); Q_CORE_EXPORT QString QStringList_join(const QStringList &list, QLatin1String sep); QStringList Q_CORE_EXPORT QStringList_filter(const QStringList *that, QStringView str, Qt::CaseSensitivity cs); @@ -185,8 +185,8 @@ namespace QtPrivate { #if QT_CONFIG(regularexpression) void Q_CORE_EXPORT QStringList_replaceInStrings(QStringList *that, const QRegularExpression &rx, const QString &after); QStringList Q_CORE_EXPORT QStringList_filter(const QStringList *that, const QRegularExpression &re); - int Q_CORE_EXPORT QStringList_indexOf(const QStringList *that, const QRegularExpression &re, int from); - int Q_CORE_EXPORT QStringList_lastIndexOf(const QStringList *that, const QRegularExpression &re, int from); + qsizetype Q_CORE_EXPORT QStringList_indexOf(const QStringList *that, const QRegularExpression &re, qsizetype from); + qsizetype Q_CORE_EXPORT QStringList_lastIndexOf(const QStringList *that, const QRegularExpression &re, qsizetype from); #endif // QT_CONFIG(regularexpression) } @@ -195,7 +195,7 @@ inline void QListSpecialMethods::sort(Qt::CaseSensitivity cs) QtPrivate::QStringList_sort(self(), cs); } -inline int QListSpecialMethods::removeDuplicates() +inline qsizetype QListSpecialMethods::removeDuplicates() { return QtPrivate::QStringList_removeDuplicates(self()); } @@ -284,22 +284,22 @@ inline QStringList operator+(const QList &one, const QStringList &other return n; } -inline int QStringList::indexOf(QStringView string, int from) const +inline qsizetype QStringList::indexOf(QStringView string, qsizetype from) const { return QtPrivate::indexOf(*this, string, from); } -inline int QStringList::indexOf(QLatin1String string, int from) const +inline qsizetype QStringList::indexOf(QLatin1String string, qsizetype from) const { return QtPrivate::indexOf(*this, string, from); } -inline int QStringList::lastIndexOf(QStringView string, int from) const +inline qsizetype QStringList::lastIndexOf(QStringView string, qsizetype from) const { return QtPrivate::lastIndexOf(*this, string, from); } -inline int QStringList::lastIndexOf(QLatin1String string, int from) const +inline qsizetype QStringList::lastIndexOf(QLatin1String string, qsizetype from) const { return QtPrivate::lastIndexOf(*this, string, from); } @@ -316,12 +316,12 @@ inline QStringList QListSpecialMethods::filter(const QRegularExpression return QtPrivate::QStringList_filter(self(), rx); } -inline int QStringList::indexOf(const QRegularExpression &rx, int from) const +inline qsizetype QStringList::indexOf(const QRegularExpression &rx, qsizetype from) const { return QtPrivate::QStringList_indexOf(this, rx, from); } -inline int QStringList::lastIndexOf(const QRegularExpression &rx, int from) const +inline qsizetype QStringList::lastIndexOf(const QRegularExpression &rx, qsizetype from) const { return QtPrivate::QStringList_lastIndexOf(this, rx, from); } diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index c37a2fd97c..6a699aa197 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -54,8 +54,8 @@ QT_BEGIN_NAMESPACE namespace QtPrivate { - template int indexOf(const QList &list, const U &u, int from); - template int lastIndexOf(const QList &list, const U &u, int from); + template qsizetype indexOf(const QList &list, const U &u, qsizetype from); + template qsizetype lastIndexOf(const QList &list, const U &u, qsizetype from); } template struct QListSpecialMethods @@ -79,8 +79,8 @@ class QList DataPointer d; - template friend int QtPrivate::indexOf(const QList &list, const U &u, int from); - template friend int QtPrivate::lastIndexOf(const QList &list, const U &u, int from); + template friend qsizetype QtPrivate::indexOf(const QList &list, const U &u, qsizetype from); + template friend qsizetype QtPrivate::lastIndexOf(const QList &list, const U &u, qsizetype from); public: typedef T Type; @@ -89,7 +89,7 @@ public: typedef const value_type *const_pointer; typedef value_type &reference; typedef const value_type &const_reference; - typedef int size_type; + typedef qsizetype size_type; typedef qptrdiff difference_type; typedef typename Data::iterator iterator; typedef typename Data::const_iterator const_iterator; @@ -101,7 +101,7 @@ public: using rvalue_ref = typename std::conditional::type; private: - void resize_internal(int i, Qt::Initialization); + void resize_internal(qsizetype i, Qt::Initialization); bool isValidIterator(const_iterator i) const { const std::less less = {}; @@ -115,13 +115,13 @@ public: public: QList() = default; - explicit QList(int size) + explicit QList(qsizetype size) : d(Data::allocate(size)) { if (size) d->appendInitialize(size); } - QList(int size, const T &t) + QList(qsizetype size, const T &t) : d(Data::allocate(size)) { if (size) @@ -177,27 +177,27 @@ public: return !(l == r); } - int size() const noexcept { return int(d->size); } - int count() const noexcept { return size(); } - int length() const noexcept { return size(); } + qsizetype size() const noexcept { return d->size; } + qsizetype count() const noexcept { return size(); } + qsizetype length() const noexcept { return size(); } inline bool isEmpty() const noexcept { return d->size == 0; } - void resize(int size) + void resize(qsizetype size) { resize_internal(size, Qt::Uninitialized); if (size > this->size()) d->appendInitialize(size); } - void resize(int size, parameter_type c) + void resize(qsizetype size, parameter_type c) { resize_internal(size, Qt::Uninitialized); if (size > this->size()) d->copyAppend(size - this->size(), c); } - inline int capacity() const { return int(d->constAllocatedCapacity()); } - void reserve(int size); + inline qsizetype capacity() const { return qsizetype(d->constAllocatedCapacity()); } + void reserve(qsizetype size); inline void squeeze(); void detach() { d.detach(); } @@ -220,18 +220,18 @@ public: } } - const_reference at(int i) const noexcept + const_reference at(qsizetype i) const noexcept { Q_ASSERT_X(size_t(i) < size_t(d->size), "QList::at", "index out of range"); return data()[i]; } - reference operator[](int i) + reference operator[](qsizetype i) { Q_ASSERT_X(size_t(i) < size_t(d->size), "QList::operator[]", "index out of range"); detach(); return data()[i]; } - const_reference operator[](int i) const noexcept { return at(i); } + const_reference operator[](qsizetype i) const noexcept { return at(i); } void append(const_reference t) { append(const_iterator(std::addressof(t)), const_iterator(std::addressof(t)) + 1); } void append(const_iterator i1, const_iterator i2); @@ -243,15 +243,15 @@ public: template reference emplaceBack(Args&&... args) { return *emplace(count(), std::forward(args)...); } - iterator insert(int i, parameter_type t) + iterator insert(qsizetype i, parameter_type t) { return insert(i, 1, t); } - iterator insert(int i, int n, parameter_type t); + iterator insert(qsizetype i, qsizetype n, parameter_type t); iterator insert(const_iterator before, parameter_type t) { Q_ASSERT_X(isValidIterator(before), "QList::insert", "The specified iterator argument 'before' is invalid"); return insert(before, 1, t); } - iterator insert(const_iterator before, int n, parameter_type t) + iterator insert(const_iterator before, qsizetype n, parameter_type t) { Q_ASSERT_X(isValidIterator(before), "QList::insert", "The specified iterator argument 'before' is invalid"); return insert(std::distance(constBegin(), before), n, t); @@ -261,7 +261,7 @@ public: Q_ASSERT_X(isValidIterator(before), "QList::insert", "The specified iterator argument 'before' is invalid"); return insert(std::distance(constBegin(), before), std::move(t)); } - iterator insert(int i, rvalue_ref t) { return emplace(i, std::move(t)); } + iterator insert(qsizetype i, rvalue_ref t) { return emplace(i, std::move(t)); } template iterator emplace(const_iterator before, Args&&... args) @@ -271,72 +271,72 @@ public: } template - iterator emplace(int i, Args&&... args); + iterator emplace(qsizetype i, Args&&... args); #if 0 template< class InputIt > iterator insert( const_iterator pos, InputIt first, InputIt last ); iterator insert( const_iterator pos, std::initializer_list ilist ); #endif - void replace(int i, const T &t) + void replace(qsizetype i, const T &t) { Q_ASSERT_X(i >= 0 && i < d->size, "QList::replace", "index out of range"); const T copy(t); data()[i] = copy; } - void replace(int i, rvalue_ref t) + void replace(qsizetype i, rvalue_ref t) { Q_ASSERT_X(i >= 0 && i < d->size, "QList::replace", "index out of range"); const T copy(std::move(t)); data()[i] = std::move(copy); } - void remove(int i, int n = 1); + void remove(qsizetype i, qsizetype n = 1); void removeFirst() { Q_ASSERT(!isEmpty()); remove(0); } void removeLast() { Q_ASSERT(!isEmpty()); remove(size() - 1); } value_type takeFirst() { Q_ASSERT(!isEmpty()); value_type v = std::move(first()); remove(0); return v; } value_type takeLast() { Q_ASSERT(!isEmpty()); value_type v = std::move(last()); remove(size() - 1); return v; } - QList &fill(parameter_type t, int size = -1); + QList &fill(parameter_type t, qsizetype size = -1); - int indexOf(const T &t, int from = 0) const noexcept; - int lastIndexOf(const T &t, int from = -1) const noexcept; + qsizetype indexOf(const T &t, qsizetype from = 0) const noexcept; + qsizetype lastIndexOf(const T &t, qsizetype from = -1) const noexcept; bool contains(const T &t) const noexcept { return indexOf(t) != -1; } - int count(const T &t) const noexcept + qsizetype count(const T &t) const noexcept { - return int(std::count(&*cbegin(), &*cend(), t)); + return qsizetype(std::count(&*cbegin(), &*cend(), t)); } // QList compatibility - void removeAt(int i) { remove(i); } - int removeAll(const T &t) + void removeAt(qsizetype i) { remove(i); } + qsizetype removeAll(const T &t) { const const_iterator ce = this->cend(), cit = std::find(this->cbegin(), ce, t); if (cit == ce) return 0; - int index = cit - this->cbegin(); + qsizetype index = cit - this->cbegin(); // next operation detaches, so ce, cit, t may become invalidated: const T tCopy = t; const iterator e = end(), it = std::remove(begin() + index, e, tCopy); - const int result = std::distance(it, e); + const qsizetype result = std::distance(it, e); erase(it, e); return result; } bool removeOne(const T &t) { - const int i = indexOf(t); + const qsizetype i = indexOf(t); if (i < 0) return false; remove(i); return true; } - T takeAt(int i) { T t = std::move((*this)[i]); remove(i); return t; } - void move(int from, int to) + T takeAt(qsizetype i) { T t = std::move((*this)[i]); remove(i); return t; } + void move(qsizetype from, qsizetype to) { - Q_ASSERT_X(from >= 0 && from < size(), "QList::move(int,int)", "'from' is out-of-range"); - Q_ASSERT_X(to >= 0 && to < size(), "QList::move(int,int)", "'to' is out-of-range"); + Q_ASSERT_X(from >= 0 && from < size(), "QList::move(qsizetype, qsizetype)", "'from' is out-of-range"); + Q_ASSERT_X(to >= 0 && to < size(), "QList::move(qsizetype, qsizetype)", "'to' is out-of-range"); if (from == to) // don't detach when no-op return; detach(); @@ -376,12 +376,12 @@ public: inline const T &constLast() const { Q_ASSERT(!isEmpty()); return *(end()-1); } inline bool startsWith(const T &t) const { return !isEmpty() && first() == t; } inline bool endsWith(const T &t) const { return !isEmpty() && last() == t; } - QList mid(int pos, int len = -1) const; + QList mid(qsizetype pos, qsizetype len = -1) const; - T value(int i) const { return value(i, T()); } - T value(int i, const T &defaultValue) const; + T value(qsizetype i) const { return value(i, T()); } + T value(qsizetype i, const T &defaultValue) const; - void swapItemsAt(int i, int j) { + void swapItemsAt(qsizetype i, qsizetype j) { Q_ASSERT_X(i >= 0 && i < size() && j >= 0 && j < size(), "QList::swap", "index out of range"); detach(); @@ -429,7 +429,7 @@ public: static inline QList fromVector(const QList &vector) { return vector; } inline QList toVector() const { return *this; } - template + template static QList fromReadOnlyData(const T (&t)[N]) { return QList({ nullptr, const_cast(t), N }); @@ -444,7 +444,7 @@ QList(InputIterator, InputIterator) -> QList; #endif template -inline void QList::resize_internal(int newSize, Qt::Initialization) +inline void QList::resize_internal(qsizetype newSize, Qt::Initialization) { Q_ASSERT(newSize >= 0); @@ -463,7 +463,7 @@ inline void QList::resize_internal(int newSize, Qt::Initialization) } template -void QList::reserve(int asize) +void QList::reserve(qsizetype asize) { // capacity() == 0 for immutable data, so this will force a detaching below if (asize <= capacity()) { @@ -496,7 +496,7 @@ inline void QList::squeeze() } template -inline void QList::remove(int i, int n) +inline void QList::remove(qsizetype i, qsizetype n) { Q_ASSERT_X(size_t(i) + size_t(n) <= size_t(d->size), "QList::remove", "index out of range"); Q_ASSERT_X(n >= 0, "QList::remove", "invalid count"); @@ -531,7 +531,7 @@ void QList::prepend(rvalue_ref t) { insert(0, std::move(t)); } template -inline T QList::value(int i, const T &defaultValue) const +inline T QList::value(qsizetype i, const T &defaultValue) const { return size_t(i) < size_t(d->size) ? at(i) : defaultValue; } @@ -556,7 +556,7 @@ inline void QList::append(const_iterator i1, const_iterator i2) template inline typename QList::iterator -QList::insert(int i, int n, parameter_type t) +QList::insert(qsizetype i, qsizetype n, parameter_type t) { Q_ASSERT_X(size_t(i) <= size_t(d->size), "QList::insert", "index out of range"); @@ -590,7 +590,7 @@ QList::insert(int i, int n, parameter_type t) template template typename QList::iterator -QList::emplace(int i, Args&&... args) +QList::emplace(qsizetype i, Args&&... args) { Q_ASSERT_X(i >= 0 && i <= d->size, "QList::insert", "index out of range"); @@ -631,15 +631,15 @@ typename QList::iterator QList::erase(const_iterator abegin, const_iterato Q_ASSERT_X(isValidIterator(aend), "QList::erase", "The specified iterator argument 'aend' is invalid"); Q_ASSERT(aend >= abegin); - int i = std::distance(d.constBegin(), abegin); - int n = std::distance(abegin, aend); + qsizetype i = std::distance(d.constBegin(), abegin); + qsizetype n = std::distance(abegin, aend); remove(i, n); return d.begin() + i; } template -inline QList &QList::fill(parameter_type t, int newSize) +inline QList &QList::fill(parameter_type t, qsizetype newSize) { if (newSize == -1) newSize = size(); @@ -661,22 +661,22 @@ inline QList &QList::fill(parameter_type t, int newSize) namespace QtPrivate { template -int indexOf(const QList &vector, const U &u, int from) +qsizetype indexOf(const QList &vector, const U &u, qsizetype from) { if (from < 0) - from = qMax(from + vector.size(), 0); + from = qMax(from + vector.size(), qsizetype(0)); if (from < vector.size()) { auto n = vector.begin() + from - 1; auto e = vector.end(); while (++n != e) if (*n == u) - return int(n - vector.begin()); + return qsizetype(n - vector.begin()); } return -1; } template -int lastIndexOf(const QList &vector, const U &u, int from) +qsizetype lastIndexOf(const QList &vector, const U &u, qsizetype from) { if (from < 0) from += vector.d->size; @@ -687,7 +687,7 @@ int lastIndexOf(const QList &vector, const U &u, int from) auto n = vector.begin() + from + 1; while (n != b) { if (*--n == u) - return int(n - b); + return qsizetype(n - b); } } return -1; @@ -695,19 +695,19 @@ int lastIndexOf(const QList &vector, const U &u, int from) } template -int QList::indexOf(const T &t, int from) const noexcept +qsizetype QList::indexOf(const T &t, qsizetype from) const noexcept { return QtPrivate::indexOf(*this, t, from); } template -int QList::lastIndexOf(const T &t, int from) const noexcept +qsizetype QList::lastIndexOf(const T &t, qsizetype from) const noexcept { return QtPrivate::lastIndexOf(*this, t, from); } template -inline QList QList::mid(int pos, int len) const +inline QList QList::mid(qsizetype pos, qsizetype len) const { qsizetype p = pos; qsizetype l = len; diff --git a/src/gui/itemmodels/qstandarditemmodel.cpp b/src/gui/itemmodels/qstandarditemmodel.cpp index ebb4d641eb..869994d428 100644 --- a/src/gui/itemmodels/qstandarditemmodel.cpp +++ b/src/gui/itemmodels/qstandarditemmodel.cpp @@ -3132,7 +3132,7 @@ QMimeData *QStandardItemModel::mimeData(const QModelIndexList &indexes) const if (itemsSet.contains(item)) //if the item is selection 'top-level', stream its position stream << item->row() << item->column(); - stream << *item << item->columnCount() << item->d_ptr->children.count(); + stream << *item << item->columnCount() << int(item->d_ptr->children.count()); stack += item->d_ptr->children; } diff --git a/src/gui/painting/qpdf_p.h b/src/gui/painting/qpdf_p.h index c277539cfa..e775406e65 100644 --- a/src/gui/painting/qpdf_p.h +++ b/src/gui/painting/qpdf_p.h @@ -86,6 +86,7 @@ namespace QPdf { ByteStream &operator <<(const ByteStream &src); ByteStream &operator <<(qreal val); ByteStream &operator <<(int val); + ByteStream &operator <<(qint64 val) { return (*this << int(val)); } ByteStream &operator <<(const QPointF &p); // Note that the stream may be invalidated by calls that insert data. QIODevice *stream(); diff --git a/src/gui/rhi/qrhivulkan.cpp b/src/gui/rhi/qrhivulkan.cpp index ee75b0eb37..32515ea31a 100644 --- a/src/gui/rhi/qrhivulkan.cpp +++ b/src/gui/rhi/qrhivulkan.cpp @@ -505,7 +505,7 @@ bool QRhiVulkan::create(QRhi::Flags flags) for (const VkExtensionProperties &p : qAsConst(extProps)) devExts.append({ p.extensionName, p.specVersion }); } - qCDebug(QRHI_LOG_INFO, "%d device extensions available", devExts.count()); + qCDebug(QRHI_LOG_INFO, "%d device extensions available", int(devExts.count())); QVector requestedDevExts; requestedDevExts.append("VK_KHR_swapchain"); diff --git a/src/gui/text/qtextdocument_p.cpp b/src/gui/text/qtextdocument_p.cpp index 5198425b26..94efb4a94d 100644 --- a/src/gui/text/qtextdocument_p.cpp +++ b/src/gui/text/qtextdocument_p.cpp @@ -877,7 +877,7 @@ bool QTextDocumentPrivate::unite(uint f) int QTextDocumentPrivate::undoRedo(bool undo) { - PMDEBUG("%s, undoState=%d, undoStack size=%d", undo ? "undo:" : "redo:", undoState, undoStack.size()); + PMDEBUG("%s, undoState=%d, undoStack size=%d", undo ? "undo:" : "redo:", undoState, int(undoStack.size())); if (!undoEnabled || (undo && undoState == 0) || (!undo && undoState == undoStack.size())) return -1; diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp index 53523f3abd..e9251d291b 100644 --- a/src/gui/text/qtextlayout.cpp +++ b/src/gui/text/qtextlayout.cpp @@ -1830,7 +1830,7 @@ void QTextLine::layout_helper(int maxGlyphs) int newItem = eng->findItem(line.from); Q_ASSERT(newItem >= 0); - LB_DEBUG("from: %d: item=%d, total %d, width available %f", line.from, newItem, eng->layoutData->items.size(), line.width.toReal()); + LB_DEBUG("from: %d: item=%d, total %d, width available %f", line.from, newItem, int(eng->layoutData->items.size()), line.width.toReal()); Qt::Alignment alignment = eng->option.alignment(); diff --git a/src/gui/text/qtextmarkdownimporter.cpp b/src/gui/text/qtextmarkdownimporter.cpp index caf7c097a3..72c445878c 100644 --- a/src/gui/text/qtextmarkdownimporter.cpp +++ b/src/gui/text/qtextmarkdownimporter.cpp @@ -177,7 +177,7 @@ int QTextMarkdownImporter::cbEnterBlock(int blockType, void *det) switch (blockType) { case MD_BLOCK_P: if (!m_listStack.isEmpty()) - qCDebug(lcMD, m_listItem ? "P of LI at level %d" : "P continuation inside LI at level %d", m_listStack.count()); + qCDebug(lcMD, m_listItem ? "P of LI at level %d" : "P continuation inside LI at level %d", int(m_listStack.count())); else qCDebug(lcMD, "P"); m_needsInsertBlock = true; @@ -243,7 +243,7 @@ int QTextMarkdownImporter::cbEnterBlock(int blockType, void *det) m_listFormat.setStyle(QTextListFormat::ListDisc); break; } - qCDebug(lcMD, "UL %c level %d", detail->mark, m_listStack.count() + 1); + qCDebug(lcMD, "UL %c level %d", detail->mark, int(m_listStack.count()) + 1); } break; case MD_BLOCK_OL: { if (m_needsInsertList) // list nested in an empty list @@ -255,7 +255,7 @@ int QTextMarkdownImporter::cbEnterBlock(int blockType, void *det) m_listFormat.setIndent(m_listStack.count() + 1); m_listFormat.setNumberSuffix(QChar::fromLatin1(detail->mark_delimiter)); m_listFormat.setStyle(QTextListFormat::ListDecimal); - qCDebug(lcMD, "OL xx%d level %d", detail->mark_delimiter, m_listStack.count() + 1); + qCDebug(lcMD, "OL xx%d level %d", detail->mark_delimiter, int(m_listStack.count()) + 1); } break; case MD_BLOCK_TD: { MD_BLOCK_TD_DETAIL *detail = static_cast(det); @@ -326,7 +326,7 @@ int QTextMarkdownImporter::cbLeaveBlock(int blockType, void *detail) if (Q_UNLIKELY(m_listStack.isEmpty())) { qCWarning(lcMD, "list ended unexpectedly"); } else { - qCDebug(lcMD, "list at level %d ended", m_listStack.count()); + qCDebug(lcMD, "list at level %d ended", int(m_listStack.count())); m_listStack.pop(); } break; @@ -363,7 +363,7 @@ int QTextMarkdownImporter::cbLeaveBlock(int blockType, void *detail) m_cursor->movePosition(QTextCursor::End); break; case MD_BLOCK_LI: - qCDebug(lcMD, "LI at level %d ended", m_listStack.count()); + qCDebug(lcMD, "LI at level %d ended", int(m_listStack.count())); m_listItem = false; break; case MD_BLOCK_CODE: { diff --git a/src/network/kernel/qdnslookup.cpp b/src/network/kernel/qdnslookup.cpp index ab1be02b6b..f679f27b36 100644 --- a/src/network/kernel/qdnslookup.cpp +++ b/src/network/kernel/qdnslookup.cpp @@ -86,7 +86,7 @@ static void qt_qdnsmailexchangerecord_sort(QList &record // Randomize the slice of records. while (!slice.isEmpty()) { - const unsigned int pos = QRandomGenerator::global()->bounded(slice.size()); + const unsigned int pos = QRandomGenerator::global()->bounded(int(slice.size())); records[i++] = slice.takeAt(pos); } } diff --git a/src/opengl/qopenglshaderprogram.cpp b/src/opengl/qopenglshaderprogram.cpp index b786c82516..e23909961c 100644 --- a/src/opengl/qopenglshaderprogram.cpp +++ b/src/opengl/qopenglshaderprogram.cpp @@ -3782,7 +3782,7 @@ bool QOpenGLShaderProgramPrivate::linkBinary() const QByteArray cacheKey = binaryProgram.cacheKey(); if (lcOpenGLProgramDiskCache().isEnabled(QtDebugMsg)) qCDebug(lcOpenGLProgramDiskCache, "program with %d shaders, cache key %s", - binaryProgram.shaders.count(), cacheKey.constData()); + int(binaryProgram.shaders.count()), cacheKey.constData()); bool needsCompile = true; if (binCache.load(cacheKey, q->programId())) { diff --git a/src/platformsupport/kmsconvenience/qkmsdevice.cpp b/src/platformsupport/kmsconvenience/qkmsdevice.cpp index c0093c1118..e0982fe832 100644 --- a/src/platformsupport/kmsconvenience/qkmsdevice.cpp +++ b/src/platformsupport/kmsconvenience/qkmsdevice.cpp @@ -471,7 +471,7 @@ QPlatformScreen *QKmsDevice::createScreenForConnector(drmModeResPtr resources, } } qCDebug(qLcKmsDebug, "Output %s can use %d planes: %s", - connectorName.constData(), output.available_planes.count(), qPrintable(planeListStr)); + connectorName.constData(), int(output.available_planes.count()), qPrintable(planeListStr)); // This is for the EGLDevice/EGLStream backend. On some of those devices one // may want to target a pre-configured plane. It is probably useless for diff --git a/src/plugins/platforms/android/qandroidinputcontext.cpp b/src/plugins/platforms/android/qandroidinputcontext.cpp index 2fb2b24890..28d4e00762 100644 --- a/src/plugins/platforms/android/qandroidinputcontext.cpp +++ b/src/plugins/platforms/android/qandroidinputcontext.cpp @@ -1173,7 +1173,7 @@ void QAndroidInputContext::focusObjectStartComposing() QInputMethodEvent event(m_composingText, { { QInputMethodEvent::Cursor, absoluteCursorPos - m_composingTextStart, 1 }, - { QInputMethodEvent::TextFormat, 0, m_composingText.length(), underlined } + { QInputMethodEvent::TextFormat, 0, int(m_composingText.length()), underlined } }); event.setCommitString({}, m_composingTextStart - absoluteCursorPos, m_composingText.length()); @@ -1450,7 +1450,7 @@ jboolean QAndroidInputContext::setComposingText(const QString &text, jint newCur underlined.setFontUnderline(true); event = QInputMethodEvent(m_composingText, { - { QInputMethodEvent::TextFormat, 0, m_composingText.length(), underlined }, + { QInputMethodEvent::TextFormat, 0, int(m_composingText.length()), underlined }, { QInputMethodEvent::Cursor, m_composingCursor - m_composingTextStart, 1 } }); diff --git a/src/tools/moc/generator.cpp b/src/tools/moc/generator.cpp index fcf6b37876..5178e90471 100644 --- a/src/tools/moc/generator.cpp +++ b/src/tools/moc/generator.cpp @@ -243,7 +243,7 @@ void Generator::generateCode() // const int constCharArraySizeLimit = 65535; fprintf(out, "struct qt_meta_stringdata_%s_t {\n", qualifiedClassNameIdentifier.constData()); - fprintf(out, " const uint offsetsAndSize[%d];\n", strings.size()*2); + fprintf(out, " const uint offsetsAndSize[%d];\n", int(strings.size()*2)); { int stringDataLength = 0; int stringDataCounter = 0; @@ -352,7 +352,7 @@ void Generator::generateCode() fprintf(out, "\n // content:\n"); fprintf(out, " %4d, // revision\n", int(QMetaObjectPrivate::OutputRevision)); fprintf(out, " %4d, // classname\n", stridx(cdef->qualified)); - fprintf(out, " %4d, %4d, // classinfo\n", cdef->classInfoList.count(), cdef->classInfoList.count() ? index : 0); + fprintf(out, " %4d, %4d, // classinfo\n", int(cdef->classInfoList.count()), int(cdef->classInfoList.count() ? index : 0)); index += cdef->classInfoList.count() * 2; int methodCount = cdef->signalList.count() + cdef->slotList.count() + cdef->methodList.count(); @@ -369,14 +369,14 @@ void Generator::generateCode() - methodCount // return "parameters" don't have names - cdef->constructorList.count(); // "this" parameters don't have names - fprintf(out, " %4d, %4d, // properties\n", cdef->propertyList.count(), cdef->propertyList.count() ? index : 0); + fprintf(out, " %4d, %4d, // properties\n", int(cdef->propertyList.count()), int(cdef->propertyList.count() ? index : 0)); index += cdef->propertyList.count() * QMetaObjectPrivate::IntsPerProperty; - fprintf(out, " %4d, %4d, // enums/sets\n", cdef->enumList.count(), cdef->enumList.count() ? index : 0); + fprintf(out, " %4d, %4d, // enums/sets\n", int(cdef->enumList.count()), cdef->enumList.count() ? index : 0); int enumsIndex = index; for (int i = 0; i < cdef->enumList.count(); ++i) index += 5 + (cdef->enumList.at(i).values.count() * 2); - fprintf(out, " %4d, %4d, // constructors\n", isConstructible ? cdef->constructorList.count() : 0, + fprintf(out, " %4d, %4d, // constructors\n", isConstructible ? int(cdef->constructorList.count()) : 0, isConstructible ? index : 0); int flags = 0; @@ -386,7 +386,7 @@ void Generator::generateCode() flags |= PropertyAccessInStaticMetaCall; } fprintf(out, " %4d, // flags\n", flags); - fprintf(out, " %4d, // signalCount\n", cdef->signalList.count()); + fprintf(out, " %4d, // signalCount\n", int(cdef->signalList.count())); // @@ -943,7 +943,7 @@ void Generator::generateEnums(int index) stridx(e.name), e.enumName.isNull() ? stridx(e.name) : stridx(e.enumName), flags, - e.values.count(), + int(e.values.count()), index); index += e.values.count() * 2; } @@ -994,18 +994,18 @@ void Generator::generateMetacall() if (methodList.size()) { needElse = true; fprintf(out, "if (_c == QMetaObject::InvokeMetaMethod) {\n"); - fprintf(out, " if (_id < %d)\n", methodList.size()); + fprintf(out, " if (_id < %d)\n", int(methodList.size())); fprintf(out, " qt_static_metacall(this, _c, _id, _a);\n"); - fprintf(out, " _id -= %d;\n }", methodList.size()); + fprintf(out, " _id -= %d;\n }", int(methodList.size())); fprintf(out, " else if (_c == QMetaObject::RegisterMethodArgumentMetaType) {\n"); - fprintf(out, " if (_id < %d)\n", methodList.size()); + fprintf(out, " if (_id < %d)\n", int(methodList.size())); if (methodsWithAutomaticTypesHelper(methodList).isEmpty()) fprintf(out, " *reinterpret_cast(_a[0]) = -1;\n"); else fprintf(out, " qt_static_metacall(this, _c, _id, _a);\n"); - fprintf(out, " _id -= %d;\n }", methodList.size()); + fprintf(out, " _id -= %d;\n }", int(methodList.size())); } @@ -1020,7 +1020,7 @@ void Generator::generateMetacall() " || _c == QMetaObject::RegisterQPropertyObserver\n" " || _c == QMetaObject::SetQPropertyBinding) {\n" " qt_static_metacall(this, _c, _id, _a);\n" - " _id -= %d;\n }", cdef->propertyList.count()); + " _id -= %d;\n }", int(cdef->propertyList.count())); fprintf(out, "\n#endif // QT_NO_PROPERTIES"); } if (methodList.size() || cdef->propertyList.size()) diff --git a/src/widgets/itemviews/qheaderview.cpp b/src/widgets/itemviews/qheaderview.cpp index 7751c756fe..3c5469f128 100644 --- a/src/widgets/itemviews/qheaderview.cpp +++ b/src/widgets/itemviews/qheaderview.cpp @@ -2119,7 +2119,7 @@ void QHeaderViewPrivate::_q_sectionsAboutToBeChanged(const QList= 0 && lastSectionLogicalIdx < sectionItems.count()) { const int visual = visualIndex(lastSectionLogicalIdx); diff --git a/src/widgets/itemviews/qtreeview.cpp b/src/widgets/itemviews/qtreeview.cpp index c4a2a31dde..e46df16953 100644 --- a/src/widgets/itemviews/qtreeview.cpp +++ b/src/widgets/itemviews/qtreeview.cpp @@ -2171,7 +2171,7 @@ int QTreeView::verticalOffset() const // ### find a faster way to do this d->executePostedLayout(); int offset = 0; - const int cnt = std::min(d->viewItems.count(), verticalScrollBar()->value()); + const int cnt = qMin(d->viewItems.count(), verticalScrollBar()->value()); for (int i = 0; i < cnt; ++i) offset += d->itemHeight(i); return offset; diff --git a/src/widgets/widgets/qdatetimeedit.cpp b/src/widgets/widgets/qdatetimeedit.cpp index d5ce003067..01f22b2dd6 100644 --- a/src/widgets/widgets/qdatetimeedit.cpp +++ b/src/widgets/widgets/qdatetimeedit.cpp @@ -1860,7 +1860,7 @@ int QDateTimeEditPrivate::closestSection(int pos, bool forward) const const QString text = displayText(); if (text.size() - pos < separators.last().size() + 1) - return forward ? LastSectionIndex : sectionNodes.size() - 1; + return forward ? LastSectionIndex : int(sectionNodes.size() - 1); updateCache(value, text); for (int i=0; i rects; std::copy(r.begin(), r.end(), std::back_inserter(rects)); - QTEST(rects.size(), "numRects"); + QTEST(int(rects.size()), "numRects"); QTEST(rects, "rects"); } diff --git a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp index aeb5c367da..0868ec04f8 100644 --- a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp +++ b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp @@ -4817,8 +4817,8 @@ void tst_QNetworkReply::ioPostToHttpFromSocket() QCOMPARE(reply->readAll().trimmed(), md5sum(data).toHex()); - QTEST(authenticationRequiredSpy.count(), "authenticationRequiredCount"); - QTEST(proxyAuthenticationRequiredSpy.count(), "proxyAuthenticationRequiredCount"); + QTEST(int(authenticationRequiredSpy.count()), "authenticationRequiredCount"); + QTEST(int(proxyAuthenticationRequiredSpy.count()), "proxyAuthenticationRequiredCount"); } void tst_QNetworkReply::ioPostToHttpFromSocketSynchronous_data() diff --git a/tests/auto/widgets/widgets/qdialogbuttonbox/tst_qdialogbuttonbox.cpp b/tests/auto/widgets/widgets/qdialogbuttonbox/tst_qdialogbuttonbox.cpp index df4a138724..f53988908a 100644 --- a/tests/auto/widgets/widgets/qdialogbuttonbox/tst_qdialogbuttonbox.cpp +++ b/tests/auto/widgets/widgets/qdialogbuttonbox/tst_qdialogbuttonbox.cpp @@ -191,7 +191,7 @@ void tst_QDialogButtonBox::testConstructor3() QDialogButtonBox buttonBox(buttons, (Qt::Orientation)orientation); QCOMPARE(int(buttonBox.orientation()), orientation); - QTEST(buttonBox.buttons().count(), "buttonCount"); + QTEST(int(buttonBox.buttons().count()), "buttonCount"); } void tst_QDialogButtonBox::testConstructor4_data() @@ -226,7 +226,7 @@ void tst_QDialogButtonBox::testConstructor4() QDialogButtonBox buttonBox(buttons); QCOMPARE(buttonBox.orientation(), Qt::Horizontal); - QTEST(buttonBox.buttons().count(), "buttonCount"); + QTEST(int(buttonBox.buttons().count()), "buttonCount"); } void tst_QDialogButtonBox::setOrientation_data() @@ -292,9 +292,9 @@ void tst_QDialogButtonBox::addButton1() QCOMPARE(buttonBox.buttons().count(), 0); QPushButton *button = new QPushButton(); buttonBox.addButton(button, role); - QTEST(buttonBox.buttons().count(), "totalCount"); + QTEST(int(buttonBox.buttons().count()), "totalCount"); QList children = buttonBox.findChildren(); - QTEST(children.count(), "totalCount"); + QTEST(int(children.count()), "totalCount"); delete button; } @@ -319,9 +319,9 @@ void tst_QDialogButtonBox::addButton2() QDialogButtonBox buttonBox; QCOMPARE(buttonBox.buttons().count(), 0); buttonBox.addButton(text, role); - QTEST(buttonBox.buttons().count(), "totalCount"); + QTEST(int(buttonBox.buttons().count()), "totalCount"); QList children = buttonBox.findChildren(); - QTEST(children.count(), "totalCount"); + QTEST(int(children.count()), "totalCount"); } void tst_QDialogButtonBox::addButton3_data() @@ -346,9 +346,9 @@ void tst_QDialogButtonBox::addButton3() QDialogButtonBox buttonBox; QCOMPARE(buttonBox.buttons().count(), 0); buttonBox.addButton(button); - QTEST(buttonBox.buttons().count(), "totalCount"); + QTEST(int(buttonBox.buttons().count()), "totalCount"); QList children = buttonBox.findChildren(); - QTEST(children.count(), "totalCount"); + QTEST(int(children.count()), "totalCount"); } void tst_QDialogButtonBox::clear_data() @@ -389,7 +389,7 @@ void tst_QDialogButtonBox::removeButton() QCOMPARE(buttonBox.buttons().count(), 0); QPushButton *button = new QPushButton("RemoveButton test"); buttonBox.addButton(button, roleToAdd); - QTEST(buttonBox.buttons().count(), "expectedCount"); + QTEST(int(buttonBox.buttons().count()), "expectedCount"); buttonBox.removeButton(button); QCOMPARE(buttonBox.buttons().count(), 0); @@ -622,9 +622,9 @@ void tst_QDialogButtonBox::testSignals() if (clicked2.count() > 0) QCOMPARE(qvariant_cast(clicked2.at(0).at(0)), clickMe); - QTEST(accept.count(), "acceptCount"); - QTEST(reject.count(), "rejectCount"); - QTEST(helpRequested.count(), "helpRequestedCount"); + QTEST(int(accept.count()), "acceptCount"); + QTEST(int(reject.count()), "rejectCount"); + QTEST(int(helpRequested.count()), "helpRequestedCount"); } void tst_QDialogButtonBox::testSignalOrder() diff --git a/tests/auto/widgets/widgets/qgroupbox/tst_qgroupbox.cpp b/tests/auto/widgets/widgets/qgroupbox/tst_qgroupbox.cpp index 4fb5d262ca..a164be8712 100644 --- a/tests/auto/widgets/widgets/qgroupbox/tst_qgroupbox.cpp +++ b/tests/auto/widgets/widgets/qgroupbox/tst_qgroupbox.cpp @@ -391,7 +391,7 @@ void tst_QGroupBox::clicked() else QTest::mouseClick(&testWidget, Qt::LeftButton); - QTEST(spy.count(), "clickedCount"); + QTEST(int(spy.count()), "clickedCount"); if (spy.count() > 0) QTEST(spy.at(0).at(0).toBool(), "finalCheck"); QTEST(testWidget.isChecked(), "finalCheck"); diff --git a/tests/auto/widgets/widgets/qtabbar/tst_qtabbar.cpp b/tests/auto/widgets/widgets/qtabbar/tst_qtabbar.cpp index 1cb6c6831f..502535502d 100644 --- a/tests/auto/widgets/widgets/qtabbar/tst_qtabbar.cpp +++ b/tests/auto/widgets/widgets/qtabbar/tst_qtabbar.cpp @@ -247,7 +247,7 @@ void tst_QTabBar::removeTab() tabbar.setCurrentIndex(currentIndex); QSignalSpy spy(&tabbar, SIGNAL(currentChanged(int))); tabbar.removeTab(deleteIndex); - QTEST(spy.count(), "spyCount"); + QTEST(int(spy.count()), "spyCount"); QTEST(tabbar.currentIndex(), "finalIndex"); } @@ -278,7 +278,7 @@ void tst_QTabBar::hideTab() tabbar.setCurrentIndex(currentIndex); QSignalSpy spy(&tabbar, &QTabBar::currentChanged); tabbar.setTabVisible(hideIndex, false); - QTEST(spy.count(), "spyCount"); + QTEST(int(spy.count()), "spyCount"); QTEST(tabbar.currentIndex(), "finalIndex"); } -- cgit v1.2.3