Fix deprecated use of QBA/Q*String::count

'Use size() or length() instead'

Change-Id: I284fce29727c4c1ec9ea38a4e8ea13a9e0af5390
Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
This commit is contained in:
Mårten Nordheim 2022-03-15 13:02:07 +01:00
parent e494b39b33
commit 6eda249402
16 changed files with 40 additions and 40 deletions

View File

@ -1089,7 +1089,7 @@ void QDir::setSearchPaths(const QString &prefix, const QStringList &searchPaths)
return; return;
} }
for (int i = 0; i < prefix.count(); ++i) { for (int i = 0; i < prefix.length(); ++i) {
if (!prefix.at(i).isLetterOrNumber()) { if (!prefix.at(i).isLetterOrNumber()) {
qWarning("QDir::setSearchPaths: Prefix can only contain letters or numbers"); qWarning("QDir::setSearchPaths: Prefix can only contain letters or numbers");
return; return;

View File

@ -93,7 +93,7 @@ static bool variantToString(const QVariant &arg, QString &out)
} else if (argType == QMetaType::QByteArray) { } else if (argType == QMetaType::QByteArray) {
out += QLatin1Char('{'); out += QLatin1Char('{');
QByteArray list = arg.toByteArray(); QByteArray list = arg.toByteArray();
for (int i = 0; i < list.count(); ++i) { for (int i = 0; i < list.length(); ++i) {
out += QString::number(list.at(i)); out += QString::number(list.at(i));
out += QLatin1String(", "); out += QLatin1String(", ");
} }

View File

@ -1031,7 +1031,7 @@ int QKeySequence::assign(const QString &ks, QKeySequence::SequenceFormat format)
// in them.. (Let's hope no one translate with a comma in it:) // in them.. (Let's hope no one translate with a comma in it:)
p = keyseq.indexOf(QLatin1Char(',')); p = keyseq.indexOf(QLatin1Char(','));
if (-1 != p) { if (-1 != p) {
if (p == keyseq.count() - 1) { // Last comma 'Ctrl+,' if (p == keyseq.length() - 1) { // Last comma 'Ctrl+,'
p = -1; p = -1;
} else { } else {
if (QLatin1Char(',') == keyseq.at(p+1)) // e.g. 'Ctrl+,, Shift+,,' if (QLatin1Char(',') == keyseq.at(p+1)) // e.g. 'Ctrl+,, Shift+,,'

View File

@ -1384,7 +1384,7 @@ QByteArray QRhiGles2::pipelineCacheData()
header.rhiId = pipelineCacheRhiId(); header.rhiId = pipelineCacheRhiId();
header.arch = quint32(sizeof(void*)); header.arch = quint32(sizeof(void*));
header.programBinaryCount = m_pipelineCache.count(); header.programBinaryCount = m_pipelineCache.count();
const size_t driverStrLen = qMin(sizeof(header.driver) - 1, size_t(driverInfoStruct.deviceName.count())); const size_t driverStrLen = qMin(sizeof(header.driver) - 1, size_t(driverInfoStruct.deviceName.length()));
if (driverStrLen) if (driverStrLen)
memcpy(header.driver, driverInfoStruct.deviceName.constData(), driverStrLen); memcpy(header.driver, driverInfoStruct.deviceName.constData(), driverStrLen);
header.driver[driverStrLen] = '\0'; header.driver[driverStrLen] = '\0';
@ -1456,7 +1456,7 @@ void QRhiGles2::setPipelineCacheData(const QByteArray &data)
if (header.programBinaryCount == 0) if (header.programBinaryCount == 0)
return; return;
const size_t driverStrLen = qMin(sizeof(header.driver) - 1, size_t(driverInfoStruct.deviceName.count())); const size_t driverStrLen = qMin(sizeof(header.driver) - 1, size_t(driverInfoStruct.deviceName.length()));
if (strncmp(header.driver, driverInfoStruct.deviceName.constData(), driverStrLen)) { if (strncmp(header.driver, driverInfoStruct.deviceName.constData(), driverStrLen)) {
qWarning("setPipelineCacheData: OpenGL vendor/renderer/version does not match"); qWarning("setPipelineCacheData: OpenGL vendor/renderer/version does not match");
return; return;
@ -4348,7 +4348,7 @@ bool QRhiGles2::compileShader(GLuint program, const QRhiShaderStage &shaderStage
} else { } else {
shader = f->glCreateShader(toGlShaderType(shaderStage.type())); shader = f->glCreateShader(toGlShaderType(shaderStage.type()));
const char *srcStr = source.constData(); const char *srcStr = source.constData();
const GLint srcLength = source.count(); const GLint srcLength = source.length();
f->glShaderSource(shader, 1, &srcStr, &srcLength); f->glShaderSource(shader, 1, &srcStr, &srcLength);
f->glCompileShader(shader); f->glCompileShader(shader);
GLint compiled = 0; GLint compiled = 0;

View File

@ -3198,7 +3198,7 @@ QFixed QTextEngine::calculateTabWidth(int item, QFixed x) const
for (const QTextOption::Tab &tabSpec : qAsConst(tabArray)) { for (const QTextOption::Tab &tabSpec : qAsConst(tabArray)) {
QFixed tab = QFixed::fromReal(tabSpec.position) * dpiScale; QFixed tab = QFixed::fromReal(tabSpec.position) * dpiScale;
if (tab > x) { // this is the tab we need. if (tab > x) { // this is the tab we need.
int tabSectionEnd = layoutData->string.count(); int tabSectionEnd = layoutData->string.length();
if (tabSpec.type == QTextOption::RightTab || tabSpec.type == QTextOption::CenterTab) { if (tabSpec.type == QTextOption::RightTab || tabSpec.type == QTextOption::CenterTab) {
// find next tab to calculate the width required. // find next tab to calculate the width required.
tab = QFixed::fromReal(tabSpec.position); tab = QFixed::fromReal(tabSpec.position);

View File

@ -1525,7 +1525,7 @@ void QTextHtmlParserNode::applyBackgroundImage(const QString &url, const QTextDo
bool QTextHtmlParserNode::hasOnlyWhitespace() const bool QTextHtmlParserNode::hasOnlyWhitespace() const
{ {
for (int i = 0; i < text.count(); ++i) for (int i = 0; i < text.length(); ++i)
if (!text.at(i).isSpace() || text.at(i) == QChar::LineSeparator) if (!text.at(i).isSpace() || text.at(i) == QChar::LineSeparator)
return false; return false;
return true; return true;

View File

@ -360,8 +360,8 @@ void QTextOdfWriter::writeBlock(QXmlStreamWriter &writer, const QTextBlock &bloc
bool escapeNextSpace = true; bool escapeNextSpace = true;
int precedingSpaces = 0; int precedingSpaces = 0;
int exportedIndex = 0; int exportedIndex = 0;
for (int i=0; i <= fragmentText.count(); ++i) { for (int i=0; i <= fragmentText.length(); ++i) {
QChar character = (i == fragmentText.count() ? QChar() : fragmentText.at(i)); QChar character = (i == fragmentText.length() ? QChar() : fragmentText.at(i));
bool isSpace = character.unicode() == ' '; bool isSpace = character.unicode() == ' ';
// find more than one space. -> <text:s text:c="2" /> // find more than one space. -> <text:s text:c="2" />
@ -377,7 +377,7 @@ void QTextOdfWriter::writeBlock(QXmlStreamWriter &writer, const QTextBlock &bloc
exportedIndex = i; exportedIndex = i;
} }
if (i < fragmentText.count()) { if (i < fragmentText.length()) {
if (character.unicode() == 0x2028) { // soft-return if (character.unicode() == 0x2028) { // soft-return
//if (exportedIndex < i) //if (exportedIndex < i)
writer.writeCharacters(fragmentText.mid(exportedIndex, i - exportedIndex)); writer.writeCharacters(fragmentText.mid(exportedIndex, i - exportedIndex));

View File

@ -353,11 +353,11 @@ void QHttpMultiPart::setBoundary(const QByteArray &boundary)
qint64 QHttpPartPrivate::bytesAvailable() const qint64 QHttpPartPrivate::bytesAvailable() const
{ {
checkHeaderCreated(); checkHeaderCreated();
qint64 bytesAvailable = header.count(); qint64 bytesAvailable = header.length();
if (bodyDevice) { if (bodyDevice) {
bytesAvailable += bodyDevice->bytesAvailable() - readPointer; bytesAvailable += bodyDevice->bytesAvailable() - readPointer;
} else { } else {
bytesAvailable += body.count() - readPointer; bytesAvailable += body.length() - readPointer;
} }
// the device might have closed etc., so make sure we do not return a negative value // the device might have closed etc., so make sure we do not return a negative value
return qMax(bytesAvailable, (qint64) 0); return qMax(bytesAvailable, (qint64) 0);
@ -367,7 +367,7 @@ qint64 QHttpPartPrivate::readData(char *data, qint64 maxSize)
{ {
checkHeaderCreated(); checkHeaderCreated();
qint64 bytesRead = 0; qint64 bytesRead = 0;
qint64 headerDataCount = header.count(); qint64 headerDataCount = header.length();
// read header if it has not been read yet // read header if it has not been read yet
if (readPointer < headerDataCount) { if (readPointer < headerDataCount) {
@ -385,7 +385,7 @@ qint64 QHttpPartPrivate::readData(char *data, qint64 maxSize)
bytesRead += dataBytesRead; bytesRead += dataBytesRead;
readPointer += dataBytesRead; readPointer += dataBytesRead;
} else { } else {
qint64 contentBytesRead = qMin(body.count() - readPointer + headerDataCount, maxSize - bytesRead); qint64 contentBytesRead = qMin(body.length() - readPointer + headerDataCount, maxSize - bytesRead);
const char *contentData = body.constData(); const char *contentData = body.constData();
// if this method is called several times, we need to find the // if this method is called several times, we need to find the
// right offset in the content ourselves: // right offset in the content ourselves:
@ -400,11 +400,11 @@ qint64 QHttpPartPrivate::readData(char *data, qint64 maxSize)
qint64 QHttpPartPrivate::size() const qint64 QHttpPartPrivate::size() const
{ {
checkHeaderCreated(); checkHeaderCreated();
qint64 size = header.count(); qint64 size = header.length();
if (bodyDevice) { if (bodyDevice) {
size += bodyDevice->size(); size += bodyDevice->size();
} else { } else {
size += body.count(); size += body.length();
} }
return size; return size;
} }
@ -440,7 +440,7 @@ QHttpMultiPartPrivate::QHttpMultiPartPrivate() : contentType(QHttpMultiPart::Mix
+ QByteArray::fromRawData(reinterpret_cast<char *>(random), sizeof(random)).toBase64(); + QByteArray::fromRawData(reinterpret_cast<char *>(random), sizeof(random)).toBase64();
// boundary must not be longer than 70 characters, see RFC 2046, section 5.1.1 // boundary must not be longer than 70 characters, see RFC 2046, section 5.1.1
Q_ASSERT(boundary.count() <= 70); Q_ASSERT(boundary.length() <= 70);
} }
qint64 QHttpMultiPartIODevice::size() const qint64 QHttpMultiPartIODevice::size() const
@ -449,7 +449,7 @@ qint64 QHttpMultiPartIODevice::size() const
// including boundary (needed later in readData) // including boundary (needed later in readData)
if (deviceSize == -1) { if (deviceSize == -1) {
qint64 currentSize = 0; qint64 currentSize = 0;
qint64 boundaryCount = multiPart->boundary.count(); qint64 boundaryCount = multiPart->boundary.length();
for (int a = 0; a < multiPart->parts.count(); a++) { for (int a = 0; a < multiPart->parts.count(); a++) {
partOffsets.append(currentSize); partOffsets.append(currentSize);
// 4 additional bytes for the "--" before and the "\r\n" after the boundary, // 4 additional bytes for the "--" before and the "\r\n" after the boundary,
@ -491,7 +491,7 @@ qint64 QHttpMultiPartIODevice::readData(char *data, qint64 maxSize)
// skip the parts we have already read // skip the parts we have already read
while (index < multiPart->parts.count() && while (index < multiPart->parts.count() &&
readPointer >= partOffsets.at(index) + multiPart->parts.at(index).d->size() readPointer >= partOffsets.at(index) + multiPart->parts.at(index).d->size()
+ multiPart->boundary.count() + 6) // 6 == 2 boundary dashes, \r\n after boundary, \r\n after multipart + multiPart->boundary.length() + 6) // 6 == 2 boundary dashes, \r\n after boundary, \r\n after multipart
index++; index++;
// read the data // read the data
@ -499,7 +499,7 @@ qint64 QHttpMultiPartIODevice::readData(char *data, qint64 maxSize)
// check whether we need to read the boundary of the current part // check whether we need to read the boundary of the current part
QByteArray boundaryData = "--" + multiPart->boundary + "\r\n"; QByteArray boundaryData = "--" + multiPart->boundary + "\r\n";
qint64 boundaryCount = boundaryData.count(); qint64 boundaryCount = boundaryData.length();
qint64 partIndex = readPointer - partOffsets.at(index); qint64 partIndex = readPointer - partOffsets.at(index);
if (partIndex < boundaryCount) { if (partIndex < boundaryCount) {
qint64 boundaryBytesRead = qMin(boundaryCount - partIndex, maxSize - bytesRead); qint64 boundaryBytesRead = qMin(boundaryCount - partIndex, maxSize - bytesRead);
@ -532,8 +532,8 @@ qint64 QHttpMultiPartIODevice::readData(char *data, qint64 maxSize)
// check whether we need to return the final boundary // check whether we need to return the final boundary
if (bytesRead < maxSize && index == multiPart->parts.count()) { if (bytesRead < maxSize && index == multiPart->parts.count()) {
QByteArray finalBoundary = "--" + multiPart->boundary + "--\r\n"; QByteArray finalBoundary = "--" + multiPart->boundary + "--\r\n";
qint64 boundaryIndex = readPointer + finalBoundary.count() - size(); qint64 boundaryIndex = readPointer + finalBoundary.length() - size();
qint64 lastBoundaryBytesRead = qMin(finalBoundary.count() - boundaryIndex, maxSize - bytesRead); qint64 lastBoundaryBytesRead = qMin(finalBoundary.length() - boundaryIndex, maxSize - bytesRead);
memcpy(data + bytesRead, finalBoundary.constData() + boundaryIndex, lastBoundaryBytesRead); memcpy(data + bytesRead, finalBoundary.constData() + boundaryIndex, lastBoundaryBytesRead);
bytesRead += lastBoundaryBytesRead; bytesRead += lastBoundaryBytesRead;
readPointer += lastBoundaryBytesRead; readPointer += lastBoundaryBytesRead;

View File

@ -1666,7 +1666,7 @@ QNetworkRequest QNetworkAccessManagerPrivate::prepareMultipart(const QNetworkReq
// add Content-Type header if not there already // add Content-Type header if not there already
if (!request.header(QNetworkRequest::ContentTypeHeader).isValid()) { if (!request.header(QNetworkRequest::ContentTypeHeader).isValid()) {
QByteArray contentType; QByteArray contentType;
contentType.reserve(34 + multiPart->d_func()->boundary.count()); contentType.reserve(34 + multiPart->d_func()->boundary.length());
contentType += "multipart/"; contentType += "multipart/";
switch (multiPart->d_func()->contentType) { switch (multiPart->d_func()->contentType) {
case QHttpMultiPart::RelatedType: case QHttpMultiPart::RelatedType:

View File

@ -266,7 +266,7 @@ SSL* QSslContext::createSsl()
} }
if (m_supportedNPNVersions.size()) { if (m_supportedNPNVersions.size()) {
m_npnContext.data = reinterpret_cast<unsigned char *>(m_supportedNPNVersions.data()); m_npnContext.data = reinterpret_cast<unsigned char *>(m_supportedNPNVersions.data());
m_npnContext.len = m_supportedNPNVersions.count(); m_npnContext.len = m_supportedNPNVersions.length();
m_npnContext.status = QSslConfiguration::NextProtocolNegotiationNone; m_npnContext.status = QSslConfiguration::NextProtocolNegotiationNone;
// Callback's type has a parameter 'const unsigned char ** out' // Callback's type has a parameter 'const unsigned char ** out'
// since it was introduced in 1.0.2. Internally, OpenSSL's own code // since it was introduced in 1.0.2. Internally, OpenSSL's own code

View File

@ -160,7 +160,7 @@ QByteArray TlsKeyOpenSSL::derFromPem(const QByteArray &pem, QMap<QByteArray, QBy
if (der.contains("Proc-Type:")) { if (der.contains("Proc-Type:")) {
// taken from QHttpNetworkReplyPrivate::parseHeader // taken from QHttpNetworkReplyPrivate::parseHeader
int i = 0; int i = 0;
while (i < der.count()) { while (i < der.length()) {
int j = der.indexOf(':', i); // field-name int j = der.indexOf(':', i); // field-name
if (j == -1) if (j == -1)
break; break;
@ -179,7 +179,7 @@ QByteArray TlsKeyOpenSSL::derFromPem(const QByteArray &pem, QMap<QByteArray, QBy
int length = i -(hasCR ? 1: 0) - j; int length = i -(hasCR ? 1: 0) - j;
value += der.mid(j, length).trimmed(); value += der.mid(j, length).trimmed();
j = ++i; j = ++i;
} while (i < der.count() && (der.at(i) == ' ' || der.at(i) == '\t')); } while (i < der.length() && (der.at(i) == ' ' || der.at(i) == '\t'));
if (i == -1) if (i == -1)
break; // something is wrong break; // something is wrong

View File

@ -770,7 +770,7 @@ QByteArray TlsKeyGeneric::derFromPem(const QByteArray &pem, QMap<QByteArray, QBy
if (der.contains("Proc-Type:")) { if (der.contains("Proc-Type:")) {
// taken from QHttpNetworkReplyPrivate::parseHeader // taken from QHttpNetworkReplyPrivate::parseHeader
int i = 0; int i = 0;
while (i < der.count()) { while (i < der.length()) {
int j = der.indexOf(':', i); // field-name int j = der.indexOf(':', i); // field-name
if (j == -1) if (j == -1)
break; break;
@ -789,7 +789,7 @@ QByteArray TlsKeyGeneric::derFromPem(const QByteArray &pem, QMap<QByteArray, QBy
int length = i -(hasCR ? 1: 0) - j; int length = i -(hasCR ? 1: 0) - j;
value += der.mid(j, length).trimmed(); value += der.mid(j, length).trimmed();
j = ++i; j = ++i;
} while (i < der.count() && (der.at(i) == ' ' || der.at(i) == '\t')); } while (i < der.length() && (der.at(i) == ' ' || der.at(i) == '\t'));
if (i == -1) if (i == -1)
break; // something is wrong break; // something is wrong

View File

@ -154,10 +154,10 @@ namespace QTest {
QString beforeDecimalPoint = QString::number(qint64(number), 'f', 0); QString beforeDecimalPoint = QString::number(qint64(number), 'f', 0);
QString afterDecimalPoint = QString::number(number, 'f', 20); QString afterDecimalPoint = QString::number(number, 'f', 20);
afterDecimalPoint.remove(0, beforeDecimalPoint.count() + 1); afterDecimalPoint.remove(0, beforeDecimalPoint.length() + 1);
int beforeUse = qMin(beforeDecimalPoint.count(), significantDigits); int beforeUse = qMin(beforeDecimalPoint.length(), significantDigits);
int beforeRemove = beforeDecimalPoint.count() - beforeUse; int beforeRemove = beforeDecimalPoint.length() - beforeUse;
// Replace insignificant digits before the decimal point with zeros. // Replace insignificant digits before the decimal point with zeros.
beforeDecimalPoint.chop(beforeRemove); beforeDecimalPoint.chop(beforeRemove);
@ -172,14 +172,14 @@ namespace QTest {
++afterUse; ++afterUse;
int i = 0; int i = 0;
while (i < afterDecimalPoint.count() && afterDecimalPoint.at(i) == QLatin1Char('0')) { while (i < afterDecimalPoint.length() && afterDecimalPoint.at(i) == QLatin1Char('0')) {
++i; ++i;
} }
afterUse += i; afterUse += i;
} }
int afterRemove = afterDecimalPoint.count() - afterUse; int afterRemove = afterDecimalPoint.length() - afterUse;
afterDecimalPoint.chop(afterRemove); afterDecimalPoint.chop(afterRemove);
QChar separator = QLatin1Char(','); QChar separator = QLatin1Char(',');
@ -207,7 +207,7 @@ namespace QTest {
int formatResult(char * buffer, int bufferSize, T number, int significantDigits) int formatResult(char * buffer, int bufferSize, T number, int significantDigits)
{ {
QString result = formatResult(number, significantDigits); QString result = formatResult(number, significantDigits);
int size = result.count(); int size = result.length();
qstrncpy(buffer, std::move(result).toLatin1().constData(), bufferSize); qstrncpy(buffer, std::move(result).toLatin1().constData(), bufferSize);
return size; return size;
} }

View File

@ -811,7 +811,7 @@ void QAccessibleLineEdit::selection(int selectionIndex, int *startOffset, int *e
return; return;
*startOffset = lineEdit()->selectionStart(); *startOffset = lineEdit()->selectionStart();
*endOffset = *startOffset + lineEdit()->selectedText().count(); *endOffset = *startOffset + lineEdit()->selectedText().length();
} }
QString QAccessibleLineEdit::text(int startOffset, int endOffset) const QString QAccessibleLineEdit::text(int startOffset, int endOffset) const
@ -884,7 +884,7 @@ void QAccessibleLineEdit::setSelection(int selectionIndex, int startOffset, int
int QAccessibleLineEdit::characterCount() const int QAccessibleLineEdit::characterCount() const
{ {
return lineEdit()->text().count(); return lineEdit()->text().length();
} }
void QAccessibleLineEdit::scrollToSubstring(int startIndex, int endIndex) void QAccessibleLineEdit::scrollToSubstring(int startIndex, int endIndex)

View File

@ -3840,8 +3840,8 @@ void QFileDialogPrivate::_q_useNameFilter(int index)
QString fileName = lineEdit()->text(); QString fileName = lineEdit()->text();
const QString fileNameExtension = QFileInfo(fileName).suffix(); const QString fileNameExtension = QFileInfo(fileName).suffix();
if (!fileNameExtension.isEmpty() && !newNameFilterExtension.isEmpty()) { if (!fileNameExtension.isEmpty() && !newNameFilterExtension.isEmpty()) {
const int fileNameExtensionLength = fileNameExtension.count(); const int fileNameExtensionLength = fileNameExtension.length();
fileName.replace(fileName.count() - fileNameExtensionLength, fileName.replace(fileName.length() - fileNameExtensionLength,
fileNameExtensionLength, newNameFilterExtension); fileNameExtensionLength, newNameFilterExtension);
qFileDialogUi->listView->clearSelection(); qFileDialogUi->listView->clearSelection();
lineEdit()->setText(fileName); lineEdit()->setText(fileName);

View File

@ -748,7 +748,7 @@ static const int numKnownStyleHints = sizeof(knownStyleHints)/sizeof(knownStyleH
static QList<QVariant> subControlLayout(const QString& layout) static QList<QVariant> subControlLayout(const QString& layout)
{ {
QList<QVariant> buttons; QList<QVariant> buttons;
for (int i = 0; i < layout.count(); i++) { for (int i = 0; i < layout.length(); i++) {
int button = layout[i].toLatin1(); int button = layout[i].toLatin1();
switch (button) { switch (button) {
case 'm': case 'm':