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;
}
for (int i = 0; i < prefix.count(); ++i) {
for (int i = 0; i < prefix.length(); ++i) {
if (!prefix.at(i).isLetterOrNumber()) {
qWarning("QDir::setSearchPaths: Prefix can only contain letters or numbers");
return;

View File

@ -93,7 +93,7 @@ static bool variantToString(const QVariant &arg, QString &out)
} else if (argType == QMetaType::QByteArray) {
out += QLatin1Char('{');
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 += 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:)
p = keyseq.indexOf(QLatin1Char(','));
if (-1 != p) {
if (p == keyseq.count() - 1) { // Last comma 'Ctrl+,'
if (p == keyseq.length() - 1) { // Last comma 'Ctrl+,'
p = -1;
} else {
if (QLatin1Char(',') == keyseq.at(p+1)) // e.g. 'Ctrl+,, Shift+,,'

View File

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

View File

@ -3198,7 +3198,7 @@ QFixed QTextEngine::calculateTabWidth(int item, QFixed x) const
for (const QTextOption::Tab &tabSpec : qAsConst(tabArray)) {
QFixed tab = QFixed::fromReal(tabSpec.position) * dpiScale;
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) {
// find next tab to calculate the width required.
tab = QFixed::fromReal(tabSpec.position);

View File

@ -1525,7 +1525,7 @@ void QTextHtmlParserNode::applyBackgroundImage(const QString &url, const QTextDo
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)
return false;
return true;

View File

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

View File

@ -353,11 +353,11 @@ void QHttpMultiPart::setBoundary(const QByteArray &boundary)
qint64 QHttpPartPrivate::bytesAvailable() const
{
checkHeaderCreated();
qint64 bytesAvailable = header.count();
qint64 bytesAvailable = header.length();
if (bodyDevice) {
bytesAvailable += bodyDevice->bytesAvailable() - readPointer;
} 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
return qMax(bytesAvailable, (qint64) 0);
@ -367,7 +367,7 @@ qint64 QHttpPartPrivate::readData(char *data, qint64 maxSize)
{
checkHeaderCreated();
qint64 bytesRead = 0;
qint64 headerDataCount = header.count();
qint64 headerDataCount = header.length();
// read header if it has not been read yet
if (readPointer < headerDataCount) {
@ -385,7 +385,7 @@ qint64 QHttpPartPrivate::readData(char *data, qint64 maxSize)
bytesRead += dataBytesRead;
readPointer += dataBytesRead;
} else {
qint64 contentBytesRead = qMin(body.count() - readPointer + headerDataCount, maxSize - bytesRead);
qint64 contentBytesRead = qMin(body.length() - readPointer + headerDataCount, maxSize - bytesRead);
const char *contentData = body.constData();
// if this method is called several times, we need to find the
// right offset in the content ourselves:
@ -400,11 +400,11 @@ qint64 QHttpPartPrivate::readData(char *data, qint64 maxSize)
qint64 QHttpPartPrivate::size() const
{
checkHeaderCreated();
qint64 size = header.count();
qint64 size = header.length();
if (bodyDevice) {
size += bodyDevice->size();
} else {
size += body.count();
size += body.length();
}
return size;
}
@ -440,7 +440,7 @@ QHttpMultiPartPrivate::QHttpMultiPartPrivate() : contentType(QHttpMultiPart::Mix
+ QByteArray::fromRawData(reinterpret_cast<char *>(random), sizeof(random)).toBase64();
// 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
@ -449,7 +449,7 @@ qint64 QHttpMultiPartIODevice::size() const
// including boundary (needed later in readData)
if (deviceSize == -1) {
qint64 currentSize = 0;
qint64 boundaryCount = multiPart->boundary.count();
qint64 boundaryCount = multiPart->boundary.length();
for (int a = 0; a < multiPart->parts.count(); a++) {
partOffsets.append(currentSize);
// 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
while (index < multiPart->parts.count() &&
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++;
// 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
QByteArray boundaryData = "--" + multiPart->boundary + "\r\n";
qint64 boundaryCount = boundaryData.count();
qint64 boundaryCount = boundaryData.length();
qint64 partIndex = readPointer - partOffsets.at(index);
if (partIndex < boundaryCount) {
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
if (bytesRead < maxSize && index == multiPart->parts.count()) {
QByteArray finalBoundary = "--" + multiPart->boundary + "--\r\n";
qint64 boundaryIndex = readPointer + finalBoundary.count() - size();
qint64 lastBoundaryBytesRead = qMin(finalBoundary.count() - boundaryIndex, maxSize - bytesRead);
qint64 boundaryIndex = readPointer + finalBoundary.length() - size();
qint64 lastBoundaryBytesRead = qMin(finalBoundary.length() - boundaryIndex, maxSize - bytesRead);
memcpy(data + bytesRead, finalBoundary.constData() + boundaryIndex, lastBoundaryBytesRead);
bytesRead += lastBoundaryBytesRead;
readPointer += lastBoundaryBytesRead;

View File

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

View File

@ -266,7 +266,7 @@ SSL* QSslContext::createSsl()
}
if (m_supportedNPNVersions.size()) {
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;
// Callback's type has a parameter 'const unsigned char ** out'
// 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:")) {
// taken from QHttpNetworkReplyPrivate::parseHeader
int i = 0;
while (i < der.count()) {
while (i < der.length()) {
int j = der.indexOf(':', i); // field-name
if (j == -1)
break;
@ -179,7 +179,7 @@ QByteArray TlsKeyOpenSSL::derFromPem(const QByteArray &pem, QMap<QByteArray, QBy
int length = i -(hasCR ? 1: 0) - j;
value += der.mid(j, length).trimmed();
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)
break; // something is wrong

View File

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

View File

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

View File

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

View File

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

View File

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