diff options
Diffstat (limited to 'src/corelib')
86 files changed, 898 insertions, 540 deletions
diff --git a/src/corelib/animation/qabstractanimation.cpp b/src/corelib/animation/qabstractanimation.cpp index 46b01449d4..b7136dc055 100644 --- a/src/corelib/animation/qabstractanimation.cpp +++ b/src/corelib/animation/qabstractanimation.cpp @@ -220,7 +220,7 @@ QUnifiedTimer::QUnifiedTimer() : QObject(), defaultDriver(this), lastTick(0), timingInterval(DEFAULT_TIMER_INTERVAL), currentAnimationIdx(0), insideTick(false), insideRestart(false), consistentTiming(false), slowMode(false), startTimersPending(false), stopTimerPending(false), - slowdownFactor(5.0f), profilerCallback(0), + slowdownFactor(5.0f), profilerCallback(nullptr), driverStartTime(0), temporalDrift(0) { time.invalidate(); @@ -922,7 +922,7 @@ qint64 QAnimationDriver::elapsed() const The default animation driver just spins the timer... */ QDefaultAnimationDriver::QDefaultAnimationDriver(QUnifiedTimer *timer) - : QAnimationDriver(0), m_unified_timer(timer) + : QAnimationDriver(nullptr), m_unified_timer(timer) { connect(this, SIGNAL(started()), this, SLOT(startTimer())); connect(this, SIGNAL(stopped()), this, SLOT(stopTimer())); @@ -1035,7 +1035,7 @@ void QAbstractAnimationPrivate::setState(QAbstractAnimation::State newState) \sa QVariantAnimation, QAnimationGroup */ QAbstractAnimation::QAbstractAnimation(QObject *parent) - : QObject(*new QAbstractAnimationPrivate, 0) + : QObject(*new QAbstractAnimationPrivate, nullptr) { // Allow auto-add on reparent setParent(parent); @@ -1045,7 +1045,7 @@ QAbstractAnimation::QAbstractAnimation(QObject *parent) \internal */ QAbstractAnimation::QAbstractAnimation(QAbstractAnimationPrivate &dd, QObject *parent) - : QObject(dd, 0) + : QObject(dd, nullptr) { // Allow auto-add on reparent setParent(parent); diff --git a/src/corelib/animation/qanimationgroup.cpp b/src/corelib/animation/qanimationgroup.cpp index 69e2cfc9bc..729f55d68f 100644 --- a/src/corelib/animation/qanimationgroup.cpp +++ b/src/corelib/animation/qanimationgroup.cpp @@ -133,7 +133,7 @@ QAbstractAnimation *QAnimationGroup::animationAt(int index) const if (index < 0 || index >= d->animations.size()) { qWarning("QAnimationGroup::animationAt: index is out of bounds"); - return 0; + return nullptr; } return d->animations.at(index); @@ -243,14 +243,14 @@ QAbstractAnimation *QAnimationGroup::takeAnimation(int index) Q_D(QAnimationGroup); if (index < 0 || index >= d->animations.size()) { qWarning("QAnimationGroup::takeAnimation: no animation at index %d", index); - return 0; + return nullptr; } QAbstractAnimation *animation = d->animations.at(index); - QAbstractAnimationPrivate::get(animation)->group = 0; + QAbstractAnimationPrivate::get(animation)->group = nullptr; // ### removing from list before doing setParent to avoid inifinite recursion // in ChildRemoved event d->animations.removeAt(index); - animation->setParent(0); + animation->setParent(nullptr); d->animationRemoved(index, animation); return animation; } diff --git a/src/corelib/animation/qpropertyanimation.cpp b/src/corelib/animation/qpropertyanimation.cpp index 2a3572d441..c71a77e073 100644 --- a/src/corelib/animation/qpropertyanimation.cpp +++ b/src/corelib/animation/qpropertyanimation.cpp @@ -259,7 +259,7 @@ void QPropertyAnimation::updateState(QAbstractAnimation::State newState, QVariantAnimation::updateState(newState, oldState); - QPropertyAnimation *animToStop = 0; + QPropertyAnimation *animToStop = nullptr; { static QBasicMutex mutex; auto locker = qt_unique_lock(mutex); diff --git a/src/corelib/animation/qsequentialanimationgroup.cpp b/src/corelib/animation/qsequentialanimationgroup.cpp index 66e346a2fe..98ac04a14f 100644 --- a/src/corelib/animation/qsequentialanimationgroup.cpp +++ b/src/corelib/animation/qsequentialanimationgroup.cpp @@ -282,7 +282,7 @@ QPauseAnimation *QSequentialAnimationGroup::insertPause(int index, int msecs) if (index < 0 || index > d->animations.size()) { qWarning("QSequentialAnimationGroup::insertPause: index is out of bounds"); - return 0; + return nullptr; } QPauseAnimation *pause = new QPauseAnimation(msecs); @@ -430,7 +430,7 @@ void QSequentialAnimationGroupPrivate::setCurrentAnimation(int index, bool inter if (index == -1) { Q_ASSERT(animations.isEmpty()); currentAnimationIndex = -1; - currentAnimation = 0; + currentAnimation = nullptr; return; } @@ -503,7 +503,7 @@ void QSequentialAnimationGroupPrivate::_q_uncontrolledAnimationFinished() */ void QSequentialAnimationGroupPrivate::animationInsertedAt(int index) { - if (currentAnimation == 0) + if (currentAnimation == nullptr) setCurrentAnimation(0); // initialize the current animation if (currentAnimationIndex == index diff --git a/src/corelib/animation/qvariantanimation.cpp b/src/corelib/animation/qvariantanimation.cpp index 216c015732..98b02f0202 100644 --- a/src/corelib/animation/qvariantanimation.cpp +++ b/src/corelib/animation/qvariantanimation.cpp @@ -209,7 +209,7 @@ void QVariantAnimationPrivate::updateInterpolator() if (type == currentInterval.end.second.userType()) interpolator = getInterpolator(type); else - interpolator = 0; + interpolator = nullptr; //we make sure that the interpolator is always set to something if (!interpolator) @@ -445,7 +445,7 @@ QVariantAnimation::Interpolator QVariantAnimationPrivate::getInterpolator(int in { QInterpolatorVector *interpolators = registeredInterpolators(); const auto locker = qt_scoped_lock(registeredInterpolatorsMutex); - QVariantAnimation::Interpolator ret = 0; + QVariantAnimation::Interpolator ret = nullptr; if (interpolationType < interpolators->count()) { ret = interpolators->at(interpolationType); if (ret) return ret; @@ -479,7 +479,7 @@ QVariantAnimation::Interpolator QVariantAnimationPrivate::getInterpolator(int in case QMetaType::QRectF: return castToInterpolator(_q_interpolateVariant<QRectF>); default: - return 0; //this type is not handled + return nullptr; //this type is not handled } } diff --git a/src/corelib/codecs/qicucodec.cpp b/src/corelib/codecs/qicucodec.cpp index 5a778c2638..f9092277b2 100644 --- a/src/corelib/codecs/qicucodec.cpp +++ b/src/corelib/codecs/qicucodec.cpp @@ -381,7 +381,7 @@ static QTextCodec *loadQtCodec(const char *name) return QIsciiCodec::create(name); #endif - return 0; + return nullptr; } /// \threadsafe @@ -438,7 +438,7 @@ QTextCodec *QIcuCodec::defaultCodecUnlocked() { QCoreGlobalData *globalData = QCoreGlobalData::instance(); if (!globalData) - return 0; + return nullptr; QTextCodec *c = globalData->codecForLocale.loadAcquire(); if (c) return c; @@ -523,13 +523,13 @@ QTextCodec *QIcuCodec::codecForNameUnlocked(const char *name) return c; if (qt_only) - return 0; + return nullptr; // check whether there is really a converter for the name available. UConverter *conv = ucnv_open(standardName, &error); if (!conv) { qDebug("codecForName: ucnv_open failed %s %s", standardName, u_errorName(error)); - return 0; + return nullptr; } //qDebug() << "QIcuCodec: Standard name for " << name << "is" << standardName; ucnv_close(conv); @@ -552,7 +552,7 @@ QTextCodec *QIcuCodec::codecForMibUnlocked(int mib) if (mib == 2107) return codecForNameUnlocked("TSCII"); - return 0; + return nullptr; } @@ -567,7 +567,7 @@ QIcuCodec::~QIcuCodec() UConverter *QIcuCodec::getConverter(QTextCodec::ConverterState *state) const { - UConverter *conv = 0; + UConverter *conv = nullptr; if (state) { if (!state->d) { // first time @@ -609,7 +609,7 @@ QString QIcuCodec::convertToUnicode(const char *chars, int length, QTextCodec::C ucnv_toUnicode(conv, &uc, ucEnd, &chars, end, - 0, false, &error); + nullptr, false, &error); if (!U_SUCCESS(error) && error != U_BUFFER_OVERFLOW_ERROR) { qDebug("convertToUnicode failed: %s", u_errorName(error)); break; @@ -646,7 +646,7 @@ QByteArray QIcuCodec::convertFromUnicode(const QChar *unicode, int length, QText ucnv_fromUnicode(conv, &ch, chEnd, &uc, end, - 0, false, &error); + nullptr, false, &error); if (!U_SUCCESS(error)) qDebug("convertFromUnicode failed: %s", u_errorName(error)); convertedChars = ch - string.data(); diff --git a/src/corelib/codecs/qisciicodec.cpp b/src/corelib/codecs/qisciicodec.cpp index d9a86d77c7..9689818559 100644 --- a/src/corelib/codecs/qisciicodec.cpp +++ b/src/corelib/codecs/qisciicodec.cpp @@ -74,7 +74,7 @@ QTextCodec *QIsciiCodec::create(const char *name) if (qTextCodecNameMatch(name, codecs[i].name)) return new QIsciiCodec(i); } - return 0; + return nullptr; } QIsciiCodec::~QIsciiCodec() diff --git a/src/corelib/codecs/qsimplecodec.cpp b/src/corelib/codecs/qsimplecodec.cpp index 16a9b8a7c3..4e82620003 100644 --- a/src/corelib/codecs/qsimplecodec.cpp +++ b/src/corelib/codecs/qsimplecodec.cpp @@ -51,7 +51,7 @@ static const struct { quint16 values[128]; } unicodevalues[QSimpleTextCodec::numSimpleCodecs] = { // from RFC 1489, ftp://ftp.isi.edu/in-notes/rfc1489.txt - { "KOI8-R", { "csKOI8R", 0 }, 2084, + { "KOI8-R", { "csKOI8R", nullptr }, 2084, { 0x2500, 0x2502, 0x250C, 0x2510, 0x2514, 0x2518, 0x251C, 0x2524, 0x252C, 0x2534, 0x253C, 0x2580, 0x2584, 0x2588, 0x258C, 0x2590, 0x2591, 0x2592, 0x2593, 0x2320, 0x25A0, 0x2219/**/, 0x221A, 0x2248, @@ -72,7 +72,7 @@ static const struct { // it should be 0x2022 (BULLET). // from RFC 2319, ftp://ftp.isi.edu/in-notes/rfc2319.txt - { "KOI8-U", { "KOI8-RU", 0 }, 2088, + { "KOI8-U", { "KOI8-RU", nullptr }, 2088, { 0x2500, 0x2502, 0x250C, 0x2510, 0x2514, 0x2518, 0x251C, 0x2524, 0x252C, 0x2534, 0x253C, 0x2580, 0x2584, 0x2588, 0x258C, 0x2590, 0x2591, 0x2592, 0x2593, 0x2320, 0x25A0, 0x2219, 0x221A, 0x2248, @@ -97,7 +97,7 @@ static const struct { // $ for A in 8 9 A B C D E F ; do for B in 0 1 2 3 4 5 6 7 8 9 A B C D E F ; do echo 0x${A}${B} 0xFFFD ; done ; done > /tmp/digits ; for a in 8859-* ; do (awk '/^0x[89ABCDEF]/{ print $1, $2 }' < $a ; cat /tmp/digits) | sort | uniq -w4 | cut -c6- | paste '-d ' - - - - - - - - | sed -e 's/ /, /g' -e 's/$/,/' -e '$ s/,$/} },/' -e '1 s/^/{ /' > ~/tmp/$a ; done // then I inserted the files manually. - { "ISO-8859-2", {"latin2", "iso-ir-101", "csISOLatin2", 0 }, 5, + { "ISO-8859-2", {"latin2", "iso-ir-101", "csISOLatin2", nullptr }, 5, { 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087, 0x0088, 0x0089, 0x008A, 0x008B, 0x008C, 0x008D, 0x008E, 0x008F, 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097, @@ -114,7 +114,7 @@ static const struct { 0x010D, 0x00E9, 0x0119, 0x00EB, 0x011B, 0x00ED, 0x00EE, 0x010F, 0x0111, 0x0144, 0x0148, 0x00F3, 0x00F4, 0x0151, 0x00F6, 0x00F7, 0x0159, 0x016F, 0x00FA, 0x0171, 0x00FC, 0x00FD, 0x0163, 0x02D9} }, - { "ISO-8859-3", { "latin3", "iso-ir-109", "csISOLatin3", 0 }, 6, + { "ISO-8859-3", { "latin3", "iso-ir-109", "csISOLatin3", nullptr }, 6, { 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087, 0x0088, 0x0089, 0x008A, 0x008B, 0x008C, 0x008D, 0x008E, 0x008F, 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097, @@ -131,7 +131,7 @@ static const struct { 0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x00EC, 0x00ED, 0x00EE, 0x00EF, 0xFFFD, 0x00F1, 0x00F2, 0x00F3, 0x00F4, 0x0121, 0x00F6, 0x00F7, 0x011D, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x016D, 0x015D, 0x02D9} }, - { "ISO-8859-4", { "latin4", "iso-ir-110", "csISOLatin4", 0 }, 7, + { "ISO-8859-4", { "latin4", "iso-ir-110", "csISOLatin4", nullptr }, 7, { 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087, 0x0088, 0x0089, 0x008A, 0x008B, 0x008C, 0x008D, 0x008E, 0x008F, 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097, @@ -148,7 +148,7 @@ static const struct { 0x010D, 0x00E9, 0x0119, 0x00EB, 0x0117, 0x00ED, 0x00EE, 0x012B, 0x0111, 0x0146, 0x014D, 0x0137, 0x00F4, 0x00F5, 0x00F6, 0x00F7, 0x00F8, 0x0173, 0x00FA, 0x00FB, 0x00FC, 0x0169, 0x016B, 0x02D9} }, - { "ISO-8859-5", { "cyrillic", "iso-ir-144", "csISOLatinCyrillic", 0 }, 8, + { "ISO-8859-5", { "cyrillic", "iso-ir-144", "csISOLatinCyrillic", nullptr }, 8, { 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087, 0x0088, 0x0089, 0x008A, 0x008B, 0x008C, 0x008D, 0x008E, 0x008F, 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097, @@ -165,7 +165,7 @@ static const struct { 0x0448, 0x0449, 0x044A, 0x044B, 0x044C, 0x044D, 0x044E, 0x044F, 0x2116, 0x0451, 0x0452, 0x0453, 0x0454, 0x0455, 0x0456, 0x0457, 0x0458, 0x0459, 0x045A, 0x045B, 0x045C, 0x00A7, 0x045E, 0x045F} }, - { "ISO-8859-6", { "ISO-8859-6-I", "ECMA-114", "ASMO-708", "arabic", "iso-ir-127", "csISOLatinArabic", 0 }, 82, + { "ISO-8859-6", { "ISO-8859-6-I", "ECMA-114", "ASMO-708", "arabic", "iso-ir-127", "csISOLatinArabic", nullptr }, 82, { 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087, 0x0088, 0x0089, 0x008A, 0x008B, 0x008C, 0x008D, 0x008E, 0x008F, 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097, @@ -182,7 +182,7 @@ static const struct { 0x0648, 0x0649, 0x064A, 0x064B, 0x064C, 0x064D, 0x064E, 0x064F, 0x0650, 0x0651, 0x0652, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD} }, - { "ISO-8859-7", { "ECMA-118", "greek", "iso-ir-126", "csISOLatinGreek", 0 }, 10, + { "ISO-8859-7", { "ECMA-118", "greek", "iso-ir-126", "csISOLatinGreek", nullptr }, 10, { 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087, 0x0088, 0x0089, 0x008A, 0x008B, 0x008C, 0x008D, 0x008E, 0x008F, 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097, @@ -199,7 +199,7 @@ static const struct { 0x03B8, 0x03B9, 0x03BA, 0x03BB, 0x03BC, 0x03BD, 0x03BE, 0x03BF, 0x03C0, 0x03C1, 0x03C2, 0x03C3, 0x03C4, 0x03C5, 0x03C6, 0x03C7, 0x03C8, 0x03C9, 0x03CA, 0x03CB, 0x03CC, 0x03CD, 0x03CE, 0xFFFD} }, - { "ISO-8859-8", { "ISO 8859-8-I", "iso-ir-138", "hebrew", "csISOLatinHebrew", 0 }, 85, + { "ISO-8859-8", { "ISO 8859-8-I", "iso-ir-138", "hebrew", "csISOLatinHebrew", nullptr }, 85, { 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087, 0x0088, 0x0089, 0x008A, 0x008B, 0x008C, 0x008D, 0x008E, 0x008F, 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097, @@ -216,7 +216,7 @@ static const struct { 0x05D8, 0x05D9, 0x05DA, 0x05DB, 0x05DC, 0x05DD, 0x05DE, 0x05DF, 0x05E0, 0x05E1, 0x05E2, 0x05E3, 0x05E4, 0x05E5, 0x05E6, 0x05E7, 0x05E8, 0x05E9, 0x05EA, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD} }, - { "ISO-8859-9", { "iso-ir-148", "latin5", "csISOLatin5", 0 }, 12, + { "ISO-8859-9", { "iso-ir-148", "latin5", "csISOLatin5", nullptr }, 12, { 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087, 0x0088, 0x0089, 0x008A, 0x008B, 0x008C, 0x008D, 0x008E, 0x008F, 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097, @@ -233,7 +233,7 @@ static const struct { 0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x00EC, 0x00ED, 0x00EE, 0x00EF, 0x011F, 0x00F1, 0x00F2, 0x00F3, 0x00F4, 0x00F5, 0x00F6, 0x00F7, 0x00F8, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x0131, 0x015F, 0x00FF} }, - { "ISO-8859-10", { "iso-ir-157", "latin6", "ISO-8859-10:1992", "csISOLatin6", 0 }, 13, + { "ISO-8859-10", { "iso-ir-157", "latin6", "ISO-8859-10:1992", "csISOLatin6", nullptr }, 13, { 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087, 0x0088, 0x0089, 0x008A, 0x008B, 0x008C, 0x008D, 0x008E, 0x008F, 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097, @@ -250,7 +250,7 @@ static const struct { 0x010D, 0x00E9, 0x0119, 0x00EB, 0x0117, 0x00ED, 0x00EE, 0x00EF, 0x00F0, 0x0146, 0x014D, 0x00F3, 0x00F4, 0x00F5, 0x00F6, 0x0169, 0x00F8, 0x0173, 0x00FA, 0x00FB, 0x00FC, 0x00FD, 0x00FE, 0x0138} }, - { "ISO-8859-13", { 0 }, 109, + { "ISO-8859-13", { nullptr }, 109, { 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087, 0x0088, 0x0089, 0x008A, 0x008B, 0x008C, 0x008D, 0x008E, 0x008F, 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097, @@ -267,7 +267,7 @@ static const struct { 0x010D, 0x00E9, 0x017A, 0x0117, 0x0123, 0x0137, 0x012B, 0x013C, 0x0161, 0x0144, 0x0146, 0x00F3, 0x014D, 0x00F5, 0x00F6, 0x00F7, 0x0173, 0x0142, 0x015B, 0x016B, 0x00FC, 0x017C, 0x017E, 0x2019} }, - { "ISO-8859-14", { "iso-ir-199", "latin8", "iso-celtic", 0 }, 110, + { "ISO-8859-14", { "iso-ir-199", "latin8", "iso-celtic", nullptr }, 110, { 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087, 0x0088, 0x0089, 0x008A, 0x008B, 0x008C, 0x008D, 0x008E, 0x008F, 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097, @@ -284,7 +284,7 @@ static const struct { 0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x00EC, 0x00ED, 0x00EE, 0x00EF, 0x0175, 0x00F1, 0x00F2, 0x00F3, 0x00F4, 0x00F5, 0x00F6, 0x1E6B, 0x00F8, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x00FD, 0x0177, 0x00FF} }, - { "ISO-8859-16", { "iso-ir-226", "latin10", 0 }, 112, + { "ISO-8859-16", { "iso-ir-226", "latin10", nullptr }, 112, { 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087, 0x0088, 0x0089, 0x008A, 0x008B, 0x008C, 0x008D, 0x008E, 0x008F, 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097, @@ -305,7 +305,7 @@ static const struct { // next bits generated again from tables on the Unicode 3.0 CD. // $ for a in CP* ; do (awk '/^0x[89ABCDEF]/{ print $1, $2 }' < $a) | sort | sed -e 's/#UNDEF.*$/0xFFFD/' | cut -c6- | paste '-d ' - - - - - - - - | sed -e 's/ /, /g' -e 's/$/,/' -e '$ s/,$/} },/' -e '1 s/^/{ /' > ~/tmp/$a ; done - { "IBM850", { "CP850", "csPC850Multilingual", 0 }, 2009, + { "IBM850", { "CP850", "csPC850Multilingual", nullptr }, 2009, { 0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x00E0, 0x00E5, 0x00E7, 0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x00EC, 0x00C4, 0x00C5, 0x00C9, 0x00E6, 0x00C6, 0x00F4, 0x00F6, 0x00F2, 0x00FB, 0x00F9, @@ -322,7 +322,7 @@ static const struct { 0x00DE, 0x00DA, 0x00DB, 0x00D9, 0x00FD, 0x00DD, 0x00AF, 0x00B4, 0x00AD, 0x00B1, 0x2017, 0x00BE, 0x00B6, 0x00A7, 0x00F7, 0x00B8, 0x00B0, 0x00A8, 0x00B7, 0x00B9, 0x00B3, 0x00B2, 0x25A0, 0x00A0} }, - { "IBM874", { "CP874", 0 }, -874, //### what is the mib? + { "IBM874", { "CP874", nullptr }, -874, //### what is the mib? { 0x20AC, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0x2026, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014, @@ -339,7 +339,7 @@ static const struct { 0x0E48, 0x0E49, 0x0E4A, 0x0E4B, 0x0E4C, 0x0E4D, 0x0E4E, 0x0E4F, 0x0E50, 0x0E51, 0x0E52, 0x0E53, 0x0E54, 0x0E55, 0x0E56, 0x0E57, 0x0E58, 0x0E59, 0x0E5A, 0x0E5B, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD} }, - { "IBM866", { "CP866", "csIBM866", 0 }, 2086, + { "IBM866", { "CP866", "csIBM866", nullptr }, 2086, { 0x0410, 0x0411, 0x0412, 0x0413, 0x0414, 0x0415, 0x0416, 0x0417, 0x0418, 0x0419, 0x041A, 0x041B, 0x041C, 0x041D, 0x041E, 0x041F, 0x0420, 0x0421, 0x0422, 0x0423, 0x0424, 0x0425, 0x0426, 0x0427, @@ -357,7 +357,7 @@ static const struct { 0x0401, 0x0451, 0x0404, 0x0454, 0x0407, 0x0457, 0x040E, 0x045E, 0x00B0, 0x2219, 0x00B7, 0x221A, 0x2116, 0x00A4, 0x25A0, 0x00A0} }, - { "windows-1250", { "CP1250", 0 }, 2250, + { "windows-1250", { "CP1250", nullptr }, 2250, { 0x20AC, 0xFFFD, 0x201A, 0xFFFD, 0x201E, 0x2026, 0x2020, 0x2021, 0xFFFD, 0x2030, 0x0160, 0x2039, 0x015A, 0x0164, 0x017D, 0x0179, 0xFFFD, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014, @@ -374,7 +374,7 @@ static const struct { 0x010D, 0x00E9, 0x0119, 0x00EB, 0x011B, 0x00ED, 0x00EE, 0x010F, 0x0111, 0x0144, 0x0148, 0x00F3, 0x00F4, 0x0151, 0x00F6, 0x00F7, 0x0159, 0x016F, 0x00FA, 0x0171, 0x00FC, 0x00FD, 0x0163, 0x02D9} }, - { "windows-1251", { "CP1251", 0 }, 2251, + { "windows-1251", { "CP1251", nullptr }, 2251, { 0x0402, 0x0403, 0x201A, 0x0453, 0x201E, 0x2026, 0x2020, 0x2021, 0x20AC, 0x2030, 0x0409, 0x2039, 0x040A, 0x040C, 0x040B, 0x040F, 0x0452, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014, @@ -391,7 +391,7 @@ static const struct { 0x0438, 0x0439, 0x043A, 0x043B, 0x043C, 0x043D, 0x043E, 0x043F, 0x0440, 0x0441, 0x0442, 0x0443, 0x0444, 0x0445, 0x0446, 0x0447, 0x0448, 0x0449, 0x044A, 0x044B, 0x044C, 0x044D, 0x044E, 0x044F} }, - { "windows-1252", { "CP1252", 0 }, 2252, + { "windows-1252", { "CP1252", nullptr }, 2252, { 0x20AC, 0xFFFD, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021, 0x02C6, 0x2030, 0x0160, 0x2039, 0x0152, 0xFFFD, 0x017D, 0xFFFD, 0xFFFD, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014, @@ -408,7 +408,7 @@ static const struct { 0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x00EC, 0x00ED, 0x00EE, 0x00EF, 0x00F0, 0x00F1, 0x00F2, 0x00F3, 0x00F4, 0x00F5, 0x00F6, 0x00F7, 0x00F8, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x00FD, 0x00FE, 0x00FF} }, - { "windows-1253", {"CP1253", 0 }, 2253, + { "windows-1253", {"CP1253", nullptr }, 2253, { 0x20AC, 0xFFFD, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021, 0xFFFD, 0x2030, 0xFFFD, 0x2039, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014, @@ -425,7 +425,7 @@ static const struct { 0x03B8, 0x03B9, 0x03BA, 0x03BB, 0x03BC, 0x03BD, 0x03BE, 0x03BF, 0x03C0, 0x03C1, 0x03C2, 0x03C3, 0x03C4, 0x03C5, 0x03C6, 0x03C7, 0x03C8, 0x03C9, 0x03CA, 0x03CB, 0x03CC, 0x03CD, 0x03CE, 0xFFFD} }, - { "windows-1254", { "CP1254", 0 }, 2254, + { "windows-1254", { "CP1254", nullptr }, 2254, { 0x20AC, 0xFFFD, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021, 0x02C6, 0x2030, 0x0160, 0x2039, 0x0152, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014, @@ -442,7 +442,7 @@ static const struct { 0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x00EC, 0x00ED, 0x00EE, 0x00EF, 0x011F, 0x00F1, 0x00F2, 0x00F3, 0x00F4, 0x00F5, 0x00F6, 0x00F7, 0x00F8, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x0131, 0x015F, 0x00FF} }, - { "windows-1255", { "CP1255", 0 }, 2255, + { "windows-1255", { "CP1255", nullptr }, 2255, { 0x20AC, 0xFFFD, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021, 0x02C6, 0x2030, 0xFFFD, 0x2039, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014, @@ -459,7 +459,7 @@ static const struct { 0x05D8, 0x05D9, 0x05DA, 0x05DB, 0x05DC, 0x05DD, 0x05DE, 0x05DF, 0x05E0, 0x05E1, 0x05E2, 0x05E3, 0x05E4, 0x05E5, 0x05E6, 0x05E7, 0x05E8, 0x05E9, 0x05EA, 0xFFFD, 0xFFFD, 0x200E, 0x200F, 0xFFFD} }, - { "windows-1256", { "CP1256", 0 }, 2256, + { "windows-1256", { "CP1256", nullptr }, 2256, { 0x20AC, 0x067E, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021, 0x02C6, 0x2030, 0x0679, 0x2039, 0x0152, 0x0686, 0x0698, 0x0688, 0x06AF, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014, @@ -476,7 +476,7 @@ static const struct { 0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x0649, 0x064A, 0x00EE, 0x00EF, 0x064B, 0x064C, 0x064D, 0x064E, 0x00F4, 0x064F, 0x0650, 0x00F7, 0x0651, 0x00F9, 0x0652, 0x00FB, 0x00FC, 0x200E, 0x200F, 0x06D2} }, - { "windows-1257", { "CP1257", 0 }, 2257, + { "windows-1257", { "CP1257", nullptr }, 2257, { 0x20AC, 0xFFFD, 0x201A, 0xFFFD, 0x201E, 0x2026, 0x2020, 0x2021, 0xFFFD, 0x2030, 0xFFFD, 0x2039, 0xFFFD, 0x00A8, 0x02C7, 0x00B8, 0xFFFD, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014, @@ -493,7 +493,7 @@ static const struct { 0x010D, 0x00E9, 0x017A, 0x0117, 0x0123, 0x0137, 0x012B, 0x013C, 0x0161, 0x0144, 0x0146, 0x00F3, 0x014D, 0x00F5, 0x00F6, 0x00F7, 0x0173, 0x0142, 0x015B, 0x016B, 0x00FC, 0x017C, 0x017E, 0x02D9} }, - { "windows-1258", { "CP1258", 0 }, 2258, + { "windows-1258", { "CP1258", nullptr }, 2258, { 0x20AC, 0xFFFD, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021, 0x02C6, 0x2030, 0xFFFD, 0x2039, 0x0152, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014, @@ -511,7 +511,7 @@ static const struct { 0x0111, 0x00F1, 0x0323, 0x00F3, 0x00F4, 0x01A1, 0x00F6, 0x00F7, 0x00F8, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x01B0, 0x20AB, 0x00FF} }, - { "macintosh", { "Apple Roman", "MacRoman", 0 }, 2027, + { "macintosh", { "Apple Roman", "MacRoman", nullptr }, 2027, { 0x00C4, 0x00C5, 0x00C7, 0x00C9, 0x00D1, 0x00D6, 0x00DC, 0x00E1, 0x00E0, 0x00E2, 0x00E4, 0x00E3, 0x00E5, 0x00E7, 0x00E9, 0x00E8, 0x00EA, 0x00EB, 0x00ED, 0x00EC, 0x00EE, 0x00EF, 0x00F1, 0x00F3, @@ -532,7 +532,7 @@ static const struct { // This one is based on the charmap file // /usr/share/i18n/charmaps/SAMI-WS2.gz, which is manually adapted // to this format by Boerre Gaup <boerre@subdimension.com> - { "WINSAMI2", { "WS2", 0 }, -165, + { "WINSAMI2", { "WS2", nullptr }, -165, { 0x20AC, 0xFFFD, 0x010C, 0x0192, 0x010D, 0x01B7, 0x0292, 0x01EE, 0x01EF, 0x0110, 0x0160, 0x2039, 0x0152, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014, @@ -555,7 +555,7 @@ static const struct { // to iso8859-11, so we name it 8859-11 here, but recognise the name tis620 too. // $ for A in 8 9 A B C D E F ; do for B in 0 1 2 3 4 5 6 7 8 9 A B C D E F ; do echo x${A}${B} 0xFFFD ; done ; done > /tmp/digits ; (cut -c25- < TIS-620 ; cat /tmp/digits) | awk '/^x[89ABCDEF]/{ print $1, $2 }' | sed -e 's/<U/0x/' -e 's/>//' | sort | uniq -w4 | cut -c5- | paste '-d ' - - - - - - - - | sed -e 's/ /, /g' -e 's/$/,/' -e '$ s/,$/} },/' -e '1 s/^/{ /' > ~/tmp/tis-620 - { "TIS-620", { "ISO 8859-11", 0 }, 2259, // Thai character set mib enum taken from tis620 (which is byte by byte equivalent) + { "TIS-620", { "ISO 8859-11", nullptr }, 2259, // Thai character set mib enum taken from tis620 (which is byte by byte equivalent) { 0x20AC, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0x2026, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014, @@ -582,7 +582,7 @@ static const struct { Alias: r8 Alias: csHPRoman8 */ - { "hp-roman8", { "roman8", "csHPRoman8", 0 }, 2004, + { "hp-roman8", { "roman8", "csHPRoman8", nullptr }, 2004, { 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, @@ -603,7 +603,7 @@ static const struct { // if you add more chacater sets at the end, change LAST_MIB above }; -QSimpleTextCodec::QSimpleTextCodec(int i) : forwardIndex(i), reverseMap(0) +QSimpleTextCodec::QSimpleTextCodec(int i) : forwardIndex(i), reverseMap(nullptr) { } @@ -640,7 +640,7 @@ static QByteArray *buildReverseMap(int forwardIndex) QString QSimpleTextCodec::convertToUnicode(const char* chars, int len, ConverterState *) const { - if (len <= 0 || chars == 0) + if (len <= 0 || chars == nullptr) return QString(); const unsigned char * c = (const unsigned char *)chars; @@ -665,7 +665,7 @@ QByteArray QSimpleTextCodec::convertFromUnicode(const QChar *in, int length, Con QByteArray *rmap = reverseMap.loadAcquire(); if (!rmap){ rmap = buildReverseMap(this->forwardIndex); - if (!reverseMap.testAndSetRelease(0, rmap)) { + if (!reverseMap.testAndSetRelease(nullptr, rmap)) { delete rmap; rmap = reverseMap.loadAcquire(); } diff --git a/src/corelib/doc/snippets/code/src_corelib_tools_qbytearray.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qbytearray.cpp index b1dc392140..9c07a2e92c 100644 --- a/src/corelib/doc/snippets/code/src_corelib_tools_qbytearray.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_tools_qbytearray.cpp @@ -422,7 +422,20 @@ text.data(); // returns "Qt is great!" QByteArray::fromBase64("PHA+SGVsbG8/PC9wPg==", QByteArray::Base64Encoding); // returns "<p>Hello?</p>" QByteArray::fromBase64("PHA-SGVsbG8_PC9wPg==", QByteArray::Base64UrlEncoding); // returns "<p>Hello?</p>" -//! [44] +//! [44bis] + +//! [44ter] +void process(const QByteArray &); + +if (auto result = QByteArray::fromBase64Encoding(encodedData)) + process(*result); +//! [44ter] + +//! [44quater] +auto result = QByteArray::fromBase64Encoding(encodedData); +if (result.decodingStatus == QByteArray::Base64DecodingStatus::Ok) + process(result.decoded); +//! [44quater] //! [45] QByteArray text = QByteArray::fromHex("517420697320677265617421"); diff --git a/src/corelib/global/qlibraryinfo.cpp b/src/corelib/global/qlibraryinfo.cpp index f4341e34fd..aed224215c 100644 --- a/src/corelib/global/qlibraryinfo.cpp +++ b/src/corelib/global/qlibraryinfo.cpp @@ -124,12 +124,12 @@ public: QLibrarySettings *ls = qt_library_settings(); if (ls) { #ifndef QT_BUILD_QMAKE - if (ls->reloadOnQAppAvailable && QCoreApplication::instance() != 0) + if (ls->reloadOnQAppAvailable && QCoreApplication::instance() != nullptr) ls->load(); #endif return ls->settings.data(); } else { - return 0; + return nullptr; } } }; @@ -146,7 +146,7 @@ void QLibrarySettings::load() // If we get any settings here, those won't change when the application shows up. settings.reset(QLibraryInfoPrivate::findConfiguration()); #ifndef QT_BUILD_QMAKE - reloadOnQAppAvailable = (settings.data() == 0 && QCoreApplication::instance() == 0); + reloadOnQAppAvailable = (settings.data() == nullptr && QCoreApplication::instance() == nullptr); bool haveDevicePaths; bool haveEffectivePaths; bool havePaths; @@ -169,7 +169,7 @@ void QLibrarySettings::load() || children.contains(QLatin1String("Paths")); #ifndef QT_BUILD_QMAKE if (!havePaths) - settings.reset(0); + settings.reset(nullptr); #else } else { haveDevicePaths = false; @@ -212,7 +212,7 @@ QSettings *QLibraryInfoPrivate::findConfiguration() return new QSettings(qtconfig, QSettings::IniFormat); } #endif - return 0; //no luck + return nullptr; //no luck } #endif // settings @@ -749,7 +749,7 @@ QLibraryInfo::rawLocation(LibraryLocation loc, PathGroup group) // will binary-patch the Qt installation paths -- in such scenarios, Qt // will be built with a dummy path, thus the compile-time result of // strlen is meaningless. - const char * volatile path = 0; + const char * volatile path = nullptr; if (loc == PrefixPath) { path = getPrefix( #ifdef QT_BUILD_QMAKE diff --git a/src/corelib/global/qlogging.cpp b/src/corelib/global/qlogging.cpp index 3a9ff1651b..e011645605 100644 --- a/src/corelib/global/qlogging.cpp +++ b/src/corelib/global/qlogging.cpp @@ -1315,7 +1315,7 @@ static QStringList backtraceFramesForLogMessage(int frameCount) if (function.startsWith(QLatin1String("_Z"))) { QScopedPointer<char, QScopedPointerPodDeleter> demangled( - abi::__cxa_demangle(function.toUtf8(), 0, 0, 0)); + abi::__cxa_demangle(function.toUtf8(), nullptr, nullptr, nullptr)); if (demangled) function = QString::fromUtf8(qCleanupFuncinfo(demangled.data())); } diff --git a/src/corelib/io/qfile.cpp b/src/corelib/io/qfile.cpp index 95f03ef816..5320ae2986 100644 --- a/src/corelib/io/qfile.cpp +++ b/src/corelib/io/qfile.cpp @@ -251,7 +251,7 @@ QFile::QFile(QFilePrivate &dd) Constructs a QFile object. */ QFile::QFile() - : QFileDevice(*new QFilePrivate, 0) + : QFileDevice(*new QFilePrivate, nullptr) { } /*! @@ -265,7 +265,7 @@ QFile::QFile(QObject *parent) Constructs a new file object to represent the file with the given \a name. */ QFile::QFile(const QString &name) - : QFileDevice(*new QFilePrivate, 0) + : QFileDevice(*new QFilePrivate, nullptr) { Q_D(QFile); d->fileName = name; diff --git a/src/corelib/io/qfiledevice.cpp b/src/corelib/io/qfiledevice.cpp index ee619d99cc..b0aba3193c 100644 --- a/src/corelib/io/qfiledevice.cpp +++ b/src/corelib/io/qfiledevice.cpp @@ -202,7 +202,7 @@ QFileDevice::QFileDevice(QFileDevicePrivate &dd) \internal */ QFileDevice::QFileDevice() - : QIODevice(*new QFileDevicePrivate, 0) + : QIODevice(*new QFileDevicePrivate, nullptr) { } /*! diff --git a/src/corelib/io/qfilesystemengine_unix.cpp b/src/corelib/io/qfilesystemengine_unix.cpp index c3abec8989..2e81f93bcf 100644 --- a/src/corelib/io/qfilesystemengine_unix.cpp +++ b/src/corelib/io/qfilesystemengine_unix.cpp @@ -1076,14 +1076,14 @@ bool QFileSystemEngine::cloneFile(int srcfd, int dstfd, const QFileSystemMetaDat // sendfile(2) is limited in the kernel to 2G - 4k const size_t SendfileSize = 0x7ffff000; - ssize_t n = ::sendfile(dstfd, srcfd, NULL, SendfileSize); + ssize_t n = ::sendfile(dstfd, srcfd, nullptr, SendfileSize); if (n == -1) { // if we got an error here, give up and try at an upper layer return false; } while (n) { - n = ::sendfile(dstfd, srcfd, NULL, SendfileSize); + n = ::sendfile(dstfd, srcfd, nullptr, SendfileSize); if (n == -1) { // uh oh, this is probably a real error (like ENOSPC), but we have // no way to notify QFile of partial success, so just erase any work diff --git a/src/corelib/io/qfilesystemwatcher.cpp b/src/corelib/io/qfilesystemwatcher.cpp index 54460aff77..86c8963cb6 100644 --- a/src/corelib/io/qfilesystemwatcher.cpp +++ b/src/corelib/io/qfilesystemwatcher.cpp @@ -88,7 +88,7 @@ QFileSystemWatcherEngine *QFileSystemWatcherPrivate::createNativeEngine(QObject } QFileSystemWatcherPrivate::QFileSystemWatcherPrivate() - : native(0), poller(0) + : native(nullptr), poller(nullptr) { } diff --git a/src/corelib/io/qfilesystemwatcher_inotify.cpp b/src/corelib/io/qfilesystemwatcher_inotify.cpp index ca1f6cc359..888af998a5 100644 --- a/src/corelib/io/qfilesystemwatcher_inotify.cpp +++ b/src/corelib/io/qfilesystemwatcher_inotify.cpp @@ -242,7 +242,7 @@ QInotifyFileSystemWatcherEngine *QInotifyFileSystemWatcherEngine::create(QObject if (fd == -1) { fd = inotify_init(); if (fd == -1) - return 0; + return nullptr; } return new QInotifyFileSystemWatcherEngine(fd, parent); } diff --git a/src/corelib/io/qiodevice.cpp b/src/corelib/io/qiodevice.cpp index e26508e631..b89cab5e3c 100644 --- a/src/corelib/io/qiodevice.cpp +++ b/src/corelib/io/qiodevice.cpp @@ -461,7 +461,7 @@ QIODevice::QIODevice(QIODevicePrivate &dd) */ QIODevice::QIODevice() - : QObject(*new QIODevicePrivate, 0) + : QObject(*new QIODevicePrivate, nullptr) { #if defined QIODEVICE_DEBUG QFile *file = qobject_cast<QFile *>(this); diff --git a/src/corelib/io/qnoncontiguousbytedevice.cpp b/src/corelib/io/qnoncontiguousbytedevice.cpp index d1806aa12b..df0197e8eb 100644 --- a/src/corelib/io/qnoncontiguousbytedevice.cpp +++ b/src/corelib/io/qnoncontiguousbytedevice.cpp @@ -127,7 +127,7 @@ QT_BEGIN_NAMESPACE \internal */ -QNonContiguousByteDevice::QNonContiguousByteDevice() : QObject((QObject*)0) +QNonContiguousByteDevice::QNonContiguousByteDevice() : QObject((QObject*)nullptr) { } @@ -188,7 +188,7 @@ const char* QNonContiguousByteDeviceByteArrayImpl::readPointer(qint64 maximumLen { if (atEnd()) { len = -1; - return 0; + return nullptr; } if (maximumLength != -1) @@ -241,7 +241,7 @@ const char* QNonContiguousByteDeviceRingBufferImpl::readPointer(qint64 maximumLe { if (atEnd()) { len = -1; - return 0; + return nullptr; } const char *returnValue = ringBuffer->readPointerAtPosition(currentPosition, len); @@ -282,7 +282,7 @@ qint64 QNonContiguousByteDeviceRingBufferImpl::size() const QNonContiguousByteDeviceIoDeviceImpl::QNonContiguousByteDeviceIoDeviceImpl(QIODevice *d) : QNonContiguousByteDevice(), - currentReadBuffer(0), currentReadBufferSize(16*1024), + currentReadBuffer(nullptr), currentReadBufferSize(16*1024), currentReadBufferAmount(0), currentReadBufferPosition(0), totalAdvancements(0), eof(false) { @@ -301,10 +301,10 @@ const char* QNonContiguousByteDeviceIoDeviceImpl::readPointer(qint64 maximumLeng { if (eof == true) { len = -1; - return 0; + return nullptr; } - if (currentReadBuffer == 0) + if (currentReadBuffer == nullptr) currentReadBuffer = new QByteArray(currentReadBufferSize, '\0'); // lazy alloc if (maximumLength == -1) @@ -323,7 +323,7 @@ const char* QNonContiguousByteDeviceIoDeviceImpl::readPointer(qint64 maximumLeng // size was unknown before, emit a readProgress with the final size if (size() == -1) emit readProgress(totalAdvancements, totalAdvancements); - return 0; + return nullptr; } currentReadBufferAmount = haveRead; @@ -349,7 +349,7 @@ bool QNonContiguousByteDeviceIoDeviceImpl::advanceReadPointer(qint64 amount) if (currentReadBufferPosition > currentReadBufferAmount) { qint64 i = currentReadBufferPosition - currentReadBufferAmount; while (i > 0) { - if (device->getChar(0) == false) { + if (device->getChar(nullptr) == false) { emit readProgress(totalAdvancements - i, size()); return false; // ### FIXME handle eof } @@ -377,7 +377,7 @@ bool QNonContiguousByteDeviceIoDeviceImpl::reset() totalAdvancements = 0; //reset the progress counter if (currentReadBuffer) { delete currentReadBuffer; - currentReadBuffer = 0; + currentReadBuffer = nullptr; } currentReadBufferAmount = 0; currentReadBufferPosition = 0; @@ -405,7 +405,7 @@ qint64 QNonContiguousByteDeviceIoDeviceImpl::pos() const return device->pos(); } -QByteDeviceWrappingIoDevice::QByteDeviceWrappingIoDevice(QNonContiguousByteDevice *bd) : QIODevice((QObject*)0) +QByteDeviceWrappingIoDevice::QByteDeviceWrappingIoDevice(QNonContiguousByteDevice *bd) : QIODevice((QObject*)nullptr) { byteDevice = bd; connect(bd, SIGNAL(readyRead()), SIGNAL(readyRead())); diff --git a/src/corelib/io/qprocess.cpp b/src/corelib/io/qprocess.cpp index 35ca2542f7..ad2e7fb6b8 100644 --- a/src/corelib/io/qprocess.cpp +++ b/src/corelib/io/qprocess.cpp @@ -216,7 +216,7 @@ void QProcessEnvironmentPrivate::insert(const QProcessEnvironmentPrivate &other) environment variables to be removed. */ QProcessEnvironment::QProcessEnvironment() - : d(0) + : d(nullptr) { } @@ -436,18 +436,18 @@ void QProcessPrivate::Channel::clear() case PipeSource: Q_ASSERT(process); process->stdinChannel.type = Normal; - process->stdinChannel.process = 0; + process->stdinChannel.process = nullptr; break; case PipeSink: Q_ASSERT(process); process->stdoutChannel.type = Normal; - process->stdoutChannel.process = 0; + process->stdoutChannel.process = nullptr; break; } type = Normal; file.clear(); - process = 0; + process = nullptr; } /*! @@ -869,8 +869,8 @@ QProcessPrivate::QProcessPrivate() sequenceNumber = 0; exitCode = 0; exitStatus = QProcess::NormalExit; - startupSocketNotifier = 0; - deathNotifier = 0; + startupSocketNotifier = nullptr; + deathNotifier = nullptr; childStartedPipe[0] = INVALID_Q_PIPE; childStartedPipe[1] = INVALID_Q_PIPE; forkfd = -1; @@ -924,23 +924,23 @@ void QProcessPrivate::cleanup() if (stdoutChannel.notifier) { delete stdoutChannel.notifier; - stdoutChannel.notifier = 0; + stdoutChannel.notifier = nullptr; } if (stderrChannel.notifier) { delete stderrChannel.notifier; - stderrChannel.notifier = 0; + stderrChannel.notifier = nullptr; } if (stdinChannel.notifier) { delete stdinChannel.notifier; - stdinChannel.notifier = 0; + stdinChannel.notifier = nullptr; } if (startupSocketNotifier) { delete startupSocketNotifier; - startupSocketNotifier = 0; + startupSocketNotifier = nullptr; } if (deathNotifier) { delete deathNotifier; - deathNotifier = 0; + deathNotifier = nullptr; } closeChannel(&stdoutChannel); closeChannel(&stderrChannel); @@ -1229,7 +1229,7 @@ void QProcessPrivate::closeWriteChannel() #endif if (stdinChannel.notifier) { delete stdinChannel.notifier; - stdinChannel.notifier = 0; + stdinChannel.notifier = nullptr; } #ifdef Q_OS_WIN // ### Find a better fix, feeding the process little by little @@ -2615,7 +2615,7 @@ QT_END_INCLUDE_NAMESPACE QStringList QProcess::systemEnvironment() { QStringList tmp; - char *entry = 0; + char *entry = nullptr; int count = 0; while ((entry = environ[count++])) tmp << QString::fromLocal8Bit(entry); diff --git a/src/corelib/io/qprocess_unix.cpp b/src/corelib/io/qprocess_unix.cpp index 9edb4a6d11..9cd3bd531b 100644 --- a/src/corelib/io/qprocess_unix.cpp +++ b/src/corelib/io/qprocess_unix.cpp @@ -338,11 +338,11 @@ static char **_q_dupEnvironment(const QProcessEnvironmentPrivate::Map &environme { *envc = 0; if (environment.isEmpty()) - return 0; + return nullptr; char **envp = new char *[environment.count() + 2]; - envp[environment.count()] = 0; - envp[environment.count() + 1] = 0; + envp[environment.count()] = nullptr; + envp[environment.count() + 1] = nullptr; auto it = environment.constBegin(); const auto end = environment.constEnd(); @@ -390,7 +390,7 @@ void QProcessPrivate::startProcess() // Create argument list with right number of elements, and set the final // one to 0. char **argv = new char *[arguments.count() + 2]; - argv[arguments.count() + 1] = 0; + argv[arguments.count() + 1] = nullptr; // Encode the program name. QByteArray encodedProgramName = QFile::encodeName(program); @@ -437,13 +437,13 @@ void QProcessPrivate::startProcess() // Duplicate the environment. int envc = 0; - char **envp = 0; + char **envp = nullptr; if (environment.d.constData()) { envp = _q_dupEnvironment(environment.d.constData()->vars, &envc); } // Encode the working directory if it's non-empty, otherwise just pass 0. - const char *workingDirPtr = 0; + const char *workingDirPtr = nullptr; QByteArray encodedWorkingDirectory; if (!workingDirectory.isEmpty()) { encodedWorkingDirectory = QFile::encodeName(workingDirectory); @@ -596,7 +596,7 @@ bool QProcessPrivate::processStarted(QString *errorMessage) if (startupSocketNotifier) { startupSocketNotifier->setEnabled(false); startupSocketNotifier->deleteLater(); - startupSocketNotifier = 0; + startupSocketNotifier = nullptr; } qt_safe_close(childStartedPipe[0]); childStartedPipe[0] = -1; @@ -889,7 +889,7 @@ bool QProcessPrivate::waitForDeadChild() crashed = info.code != CLD_EXITED; delete deathNotifier; - deathNotifier = 0; + deathNotifier = nullptr; EINTR_LOOP(ret, forkfd_close(forkfd)); forkfd = -1; // Child is dead, don't try to kill it anymore @@ -935,7 +935,7 @@ bool QProcessPrivate::startDetached(qint64 *pid) struct sigaction noaction; memset(&noaction, 0, sizeof(noaction)); noaction.sa_handler = SIG_IGN; - ::sigaction(SIGPIPE, &noaction, 0); + ::sigaction(SIGPIPE, &noaction, nullptr); ::setsid(); @@ -964,7 +964,7 @@ bool QProcessPrivate::startDetached(qint64 *pid) char **argv = new char *[arguments.size() + 2]; for (int i = 0; i < arguments.size(); ++i) argv[i + 1] = ::strdup(QFile::encodeName(arguments.at(i)).constData()); - argv[arguments.size() + 1] = 0; + argv[arguments.size() + 1] = nullptr; // Duplicate the environment. int envc = 0; @@ -991,7 +991,7 @@ bool QProcessPrivate::startDetached(qint64 *pid) struct sigaction noaction; memset(&noaction, 0, sizeof(noaction)); noaction.sa_handler = SIG_IGN; - ::sigaction(SIGPIPE, &noaction, 0); + ::sigaction(SIGPIPE, &noaction, nullptr); // '\1' means execv failed char c = '\1'; @@ -1002,7 +1002,7 @@ bool QProcessPrivate::startDetached(qint64 *pid) struct sigaction noaction; memset(&noaction, 0, sizeof(noaction)); noaction.sa_handler = SIG_IGN; - ::sigaction(SIGPIPE, &noaction, 0); + ::sigaction(SIGPIPE, &noaction, nullptr); // '\2' means internal error char c = '\2'; diff --git a/src/corelib/io/qresource.cpp b/src/corelib/io/qresource.cpp index 44657f8398..6bdb99f97a 100644 --- a/src/corelib/io/qresource.cpp +++ b/src/corelib/io/qresource.cpp @@ -1578,7 +1578,7 @@ QAbstractFileEngine::Iterator *QResourceFileEngine::beginEntryList(QDir::Filters */ QAbstractFileEngine::Iterator *QResourceFileEngine::endEntryList() { - return 0; + return nullptr; } bool QResourceFileEngine::extension(Extension extension, const ExtensionOption *option, ExtensionReturn *output) @@ -1588,7 +1588,7 @@ bool QResourceFileEngine::extension(Extension extension, const ExtensionOption * const MapExtensionOption *options = (const MapExtensionOption*)(option); MapExtensionReturn *returnValue = static_cast<MapExtensionReturn*>(output); returnValue->address = d->map(options->offset, options->size, options->flags); - return (returnValue->address != 0); + return (returnValue->address != nullptr); } if (extension == UnMapExtension) { const UnMapExtensionOption *options = (const UnMapExtensionOption*)option; @@ -1617,7 +1617,7 @@ uchar *QResourceFileEnginePrivate::map(qint64 offset, qint64 size, QFile::Memory if (offset < 0 || size <= 0 || !resource.isValid() || add_overflow(offset, size, &end) || end > max) { q->setError(QFile::UnspecifiedError, QString()); - return 0; + return nullptr; } const uchar *address = resource.data(); diff --git a/src/corelib/io/qsavefile.cpp b/src/corelib/io/qsavefile.cpp index 0a884a7df9..067ccda3df 100644 --- a/src/corelib/io/qsavefile.cpp +++ b/src/corelib/io/qsavefile.cpp @@ -116,7 +116,7 @@ QSaveFile::QSaveFile(const QString &name) Constructs a new file object to represent the file with the given \a name. */ QSaveFile::QSaveFile(const QString &name) - : QFileDevice(*new QSaveFilePrivate, 0) + : QFileDevice(*new QSaveFilePrivate, nullptr) { Q_D(QSaveFile); d->fileName = name; diff --git a/src/corelib/io/qsettings.cpp b/src/corelib/io/qsettings.cpp index da2a790e1e..779b6f72de 100644 --- a/src/corelib/io/qsettings.cpp +++ b/src/corelib/io/qsettings.cpp @@ -206,7 +206,7 @@ QConfFile *QConfFile::fromName(const QString &fileName, bool _userPerms) ConfFileHash *usedHash = usedHashFunc(); ConfFileCache *unusedCache = unusedCacheFunc(); - QConfFile *confFile = 0; + QConfFile *confFile = nullptr; const auto locker = qt_scoped_lock(settingsGlobalMutex); if (!(confFile = usedHash->value(absPath))) { @@ -230,7 +230,7 @@ void QConfFile::clearCache() // QSettingsPrivate QSettingsPrivate::QSettingsPrivate(QSettings::Format format) - : format(format), scope(QSettings::UserScope /* nothing better to put */), iniCodec(0), fallbacks(true), + : format(format), scope(QSettings::UserScope /* nothing better to put */), iniCodec(nullptr), fallbacks(true), pendingChanges(false), status(QSettings::NoError) { } @@ -238,7 +238,7 @@ QSettingsPrivate::QSettingsPrivate(QSettings::Format format) QSettingsPrivate::QSettingsPrivate(QSettings::Format format, QSettings::Scope scope, const QString &organization, const QString &application) : format(format), scope(scope), organizationName(organization), applicationName(application), - iniCodec(0), fallbacks(true), pendingChanges(false), status(QSettings::NoError) + iniCodec(nullptr), fallbacks(true), pendingChanges(false), status(QSettings::NoError) { } @@ -927,8 +927,8 @@ QStringList QSettingsPrivate::splitArgs(const QString &s, int idx) void QConfFileSettingsPrivate::initFormat() { extension = (format == QSettings::NativeFormat) ? QLatin1String(".conf") : QLatin1String(".ini"); - readFunc = 0; - writeFunc = 0; + readFunc = nullptr; + writeFunc = nullptr; #if defined(Q_OS_MAC) caseSensitivity = (format == QSettings::NativeFormat) ? Qt::CaseSensitive : IniCaseSensitivity; #else @@ -3341,7 +3341,7 @@ bool QSettings::contains(const QString &key) const { Q_D(const QSettings); QString k = d->actualKey(key); - return d->get(k, 0); + return d->get(k, nullptr); } /*! diff --git a/src/corelib/itemmodels/qabstractitemmodel.cpp b/src/corelib/itemmodels/qabstractitemmodel.cpp index 48b72880e6..3be56f5fe6 100644 --- a/src/corelib/itemmodels/qabstractitemmodel.cpp +++ b/src/corelib/itemmodels/qabstractitemmodel.cpp @@ -61,7 +61,7 @@ Q_LOGGING_CATEGORY(lcCheckIndex, "qt.core.qabstractitemmodel.checkindex") QPersistentModelIndexData *QPersistentModelIndexData::create(const QModelIndex &index) { Q_ASSERT(index.isValid()); // we will _never_ insert an invalid index in the list - QPersistentModelIndexData *d = 0; + QPersistentModelIndexData *d = nullptr; QAbstractItemModel *model = const_cast<QAbstractItemModel *>(index.model()); QHash<QModelIndex, QPersistentModelIndexData *> &indexes = model->d_func()->persistent.indexes; const auto it = indexes.constFind(index); @@ -136,7 +136,7 @@ void QPersistentModelIndexData::destroy(QPersistentModelIndexData *data) */ QPersistentModelIndex::QPersistentModelIndex() - : d(0) + : d(nullptr) { } @@ -158,7 +158,7 @@ QPersistentModelIndex::QPersistentModelIndex(const QPersistentModelIndex &other) */ QPersistentModelIndex::QPersistentModelIndex(const QModelIndex &index) - : d(0) + : d(nullptr) { if (index.isValid()) { d = QPersistentModelIndexData::create(index); @@ -176,7 +176,7 @@ QPersistentModelIndex::~QPersistentModelIndex() { if (d && !d->ref.deref()) { QPersistentModelIndexData::destroy(d); - d = 0; + d = nullptr; } } @@ -257,7 +257,7 @@ QPersistentModelIndex &QPersistentModelIndex::operator=(const QModelIndex &other d = QPersistentModelIndexData::create(other); if (d) d->ref.ref(); } else { - d = 0; + d = nullptr; } return *this; } @@ -344,7 +344,7 @@ void *QPersistentModelIndex::internalPointer() const { if (d) return d->index.internalPointer(); - return 0; + return nullptr; } /*! @@ -442,7 +442,7 @@ const QAbstractItemModel *QPersistentModelIndex::model() const { if (d) return d->index.model(); - return 0; + return nullptr; } /*! @@ -484,7 +484,7 @@ QDebug operator<<(QDebug dbg, const QPersistentModelIndex &idx) class QEmptyItemModel : public QAbstractItemModel { public: - explicit QEmptyItemModel(QObject *parent = 0) : QAbstractItemModel(parent) {} + explicit QEmptyItemModel(QObject *parent = nullptr) : QAbstractItemModel(parent) {} QModelIndex index(int, int, const QModelIndex &) const override { return QModelIndex(); } QModelIndex parent(const QModelIndex &) const override { return QModelIndex(); } int rowCount(const QModelIndex &) const override { return 0; } @@ -1950,10 +1950,10 @@ QStringList QAbstractItemModel::mimeTypes() const QMimeData *QAbstractItemModel::mimeData(const QModelIndexList &indexes) const { if (indexes.count() <= 0) - return 0; + return nullptr; QStringList types = mimeTypes(); if (types.isEmpty()) - return 0; + return nullptr; QMimeData *data = new QMimeData(); QString format = types.at(0); QByteArray encoded; diff --git a/src/corelib/itemmodels/qabstractproxymodel.cpp b/src/corelib/itemmodels/qabstractproxymodel.cpp index c863406afd..87559cd6b2 100644 --- a/src/corelib/itemmodels/qabstractproxymodel.cpp +++ b/src/corelib/itemmodels/qabstractproxymodel.cpp @@ -159,7 +159,7 @@ QAbstractItemModel *QAbstractProxyModel::sourceModel() const { Q_D(const QAbstractProxyModel); if (d->model == QAbstractItemModelPrivate::staticEmptyModel()) - return 0; + return nullptr; return d->model; } diff --git a/src/corelib/itemmodels/qconcatenatetablesproxymodel.cpp b/src/corelib/itemmodels/qconcatenatetablesproxymodel.cpp index 0319d215a1..3afa132483 100644 --- a/src/corelib/itemmodels/qconcatenatetablesproxymodel.cpp +++ b/src/corelib/itemmodels/qconcatenatetablesproxymodel.cpp @@ -497,7 +497,7 @@ void QConcatenateTablesProxyModel::removeSourceModel(QAbstractItemModel *sourceM { Q_D(QConcatenateTablesProxyModel); Q_ASSERT(d->m_models.contains(sourceModel)); - disconnect(sourceModel, 0, this, 0); + disconnect(sourceModel, nullptr, this, nullptr); const int rowsRemoved = sourceModel->rowCount(); const int rowsPrior = d->computeRowsPrior(sourceModel); // location of removed section diff --git a/src/corelib/itemmodels/qitemselectionmodel.cpp b/src/corelib/itemmodels/qitemselectionmodel.cpp index c93a4d15b9..f4402c88dc 100644 --- a/src/corelib/itemmodels/qitemselectionmodel.cpp +++ b/src/corelib/itemmodels/qitemselectionmodel.cpp @@ -656,7 +656,7 @@ void QItemSelectionModelPrivate::initModel(QAbstractItemModel *m) SLOT(_q_layoutChanged(QList<QPersistentModelIndex>,QAbstractItemModel::LayoutChangeHint)) }, { SIGNAL(modelReset()), SLOT(reset()) }, - { 0, 0 } + { nullptr, nullptr } }; if (model == m) diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp index a66c71cff6..dc46695f80 100644 --- a/src/corelib/kernel/qcoreapplication.cpp +++ b/src/corelib/kernel/qcoreapplication.cpp @@ -530,10 +530,10 @@ void QCoreApplicationPrivate::eventDispatcherReady() { } -QBasicAtomicPointer<QThread> QCoreApplicationPrivate::theMainThread = Q_BASIC_ATOMIC_INITIALIZER(0); +QBasicAtomicPointer<QThread> QCoreApplicationPrivate::theMainThread = Q_BASIC_ATOMIC_INITIALIZER(nullptr); QThread *QCoreApplicationPrivate::mainThread() { - Q_ASSERT(theMainThread.loadRelaxed() != 0); + Q_ASSERT(theMainThread.loadRelaxed() != nullptr); return theMainThread.loadRelaxed(); } @@ -690,7 +690,7 @@ QCoreApplication::QCoreApplication(QCoreApplicationPrivate &p) #ifdef QT_NO_QOBJECT : d_ptr(&p) #else - : QObject(p, 0) + : QObject(p, nullptr) #endif { d_func()->q_ptr = this; @@ -1139,7 +1139,7 @@ bool QCoreApplication::notify(QObject *receiver, QEvent *event) static bool doNotify(QObject *receiver, QEvent *event) { - if (receiver == 0) { // serious error + if (receiver == nullptr) { // serious error qWarning("QCoreApplication::notify: Unexpected null receiver"); return true; } @@ -1388,7 +1388,7 @@ void QCoreApplicationPrivate::execCleanup() if (!aboutToQuitEmitted) emit q_func()->aboutToQuit(QCoreApplication::QPrivateSignal()); aboutToQuitEmitted = true; - QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete); + QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete); } @@ -1531,7 +1531,7 @@ void QCoreApplication::postEvent(QObject *receiver, QEvent *event, int priority) { Q_TRACE_SCOPE(QCoreApplication_postEvent, receiver, event, event->type()); - if (receiver == 0) { + if (receiver == nullptr) { qWarning("QCoreApplication::postEvent: Unexpected null receiver"); delete event; return; @@ -1635,7 +1635,7 @@ bool QCoreApplication::compressEvent(QEvent *event, QObject *receiver, QPostEven for (int i = 0; i < postedEvents->size(); ++i) { const QPostEvent &cur = postedEvents->at(i); if (cur.receiver != receiver - || cur.event == 0 + || cur.event == nullptr || cur.event->type() != event->type()) continue; // found an event for this receiver @@ -1784,7 +1784,7 @@ void QCoreApplicationPrivate::sendPostedEvents(QObject *receiver, int event_type // null out the event so if sendPostedEvents recurses, it // will ignore this one, as it's been re-posted. - const_cast<QPostEvent &>(pe).event = 0; + const_cast<QPostEvent &>(pe).event = nullptr; // re-post the copied event so it isn't lost data->postEventList.addEvent(pe_copy); @@ -1804,7 +1804,7 @@ void QCoreApplicationPrivate::sendPostedEvents(QObject *receiver, int event_type // next, update the data structure so that we're ready // for the next event. - const_cast<QPostEvent &>(pe).event = 0; + const_cast<QPostEvent &>(pe).event = nullptr; locker.unlock(); const auto relocker = qScopeGuard([&locker] { locker.lock(); }); @@ -1867,7 +1867,7 @@ void QCoreApplication::removePostedEvents(QObject *receiver, int eventType) --pe.receiver->d_func()->postedEvents; pe.event->posted = false; events.append(pe.event); - const_cast<QPostEvent &>(pe).event = 0; + const_cast<QPostEvent &>(pe).event = nullptr; } else if (!data->postEventList.recursion) { if (i != j) qSwap(data->postEventList[i], data->postEventList[j]); @@ -1929,7 +1929,7 @@ void QCoreApplicationPrivate::removePostedEvent(QEvent * event) --pe.receiver->d_func()->postedEvents; pe.event->posted = false; delete pe.event; - const_cast<QPostEvent &>(pe).event = 0; + const_cast<QPostEvent &>(pe).event = nullptr; return; } } @@ -2204,7 +2204,7 @@ QString QCoreApplication::translate(const char *context, const char *sourceText, // Declared in qglobal.h QString qtTrId(const char *id, int n) { - return QCoreApplication::translate(0, id, 0, n); + return QCoreApplication::translate(nullptr, id, nullptr, n); } bool QCoreApplicationPrivate::isTranslatorInstalled(QTranslator *translator) @@ -2956,7 +2956,7 @@ QAbstractEventDispatcher *QCoreApplication::eventDispatcher() { if (QCoreApplicationPrivate::theMainThread.loadAcquire()) return QCoreApplicationPrivate::theMainThread.loadRelaxed()->eventDispatcher(); - return 0; + return nullptr; } /*! diff --git a/src/corelib/kernel/qcoreevent.cpp b/src/corelib/kernel/qcoreevent.cpp index 4cfc749386..e3326f00d7 100644 --- a/src/corelib/kernel/qcoreevent.cpp +++ b/src/corelib/kernel/qcoreevent.cpp @@ -295,7 +295,7 @@ QT_BEGIN_NAMESPACE Contructs an event object of type \a type. */ QEvent::QEvent(Type type) - : d(0), t(type), posted(false), spont(false), m_accept(true) + : d(nullptr), t(type), posted(false), spont(false), m_accept(true) { Q_TRACE(QEvent_ctor, this, t); } diff --git a/src/corelib/kernel/qeventdispatcher_glib.cpp b/src/corelib/kernel/qeventdispatcher_glib.cpp index d9746ef6e2..92f3553247 100644 --- a/src/corelib/kernel/qeventdispatcher_glib.cpp +++ b/src/corelib/kernel/qeventdispatcher_glib.cpp @@ -114,9 +114,9 @@ static GSourceFuncs socketNotifierSourceFuncs = { socketNotifierSourcePrepare, socketNotifierSourceCheck, socketNotifierSourceDispatch, - NULL, - NULL, - NULL + nullptr, + nullptr, + nullptr }; struct GTimerSource @@ -188,9 +188,9 @@ static GSourceFuncs timerSourceFuncs = { timerSourcePrepare, timerSourceCheck, timerSourceDispatch, - NULL, - NULL, - NULL + nullptr, + nullptr, + nullptr }; struct GIdleTimerSource @@ -227,7 +227,7 @@ static gboolean idleTimerSourceCheck(GSource *source) static gboolean idleTimerSourceDispatch(GSource *source, GSourceFunc, gpointer) { GTimerSource *timerSource = reinterpret_cast<GIdleTimerSource *>(source)->timerSource; - (void) timerSourceDispatch(&timerSource->source, 0, 0); + (void) timerSourceDispatch(&timerSource->source, nullptr, nullptr); return true; } @@ -235,9 +235,9 @@ static GSourceFuncs idleTimerSourceFuncs = { idleTimerSourcePrepare, idleTimerSourceCheck, idleTimerSourceDispatch, - NULL, - NULL, - NULL + nullptr, + nullptr, + nullptr }; struct GPostEventSource @@ -267,7 +267,7 @@ static gboolean postEventSourcePrepare(GSource *s, gint *timeout) static gboolean postEventSourceCheck(GSource *source) { - return postEventSourcePrepare(source, 0); + return postEventSourcePrepare(source, nullptr); } static gboolean postEventSourceDispatch(GSource *s, GSourceFunc, gpointer) @@ -283,9 +283,9 @@ static GSourceFuncs postEventSourceFuncs = { postEventSourcePrepare, postEventSourceCheck, postEventSourceDispatch, - NULL, - NULL, - NULL + nullptr, + nullptr, + nullptr }; @@ -372,10 +372,10 @@ QEventDispatcherGlib::~QEventDispatcherGlib() d->timerSource->timerList.~QTimerInfoList(); g_source_destroy(&d->timerSource->source); g_source_unref(&d->timerSource->source); - d->timerSource = 0; + d->timerSource = nullptr; g_source_destroy(&d->idleTimerSource->source); g_source_unref(&d->idleTimerSource->source); - d->idleTimerSource = 0; + d->idleTimerSource = nullptr; // destroy socket notifier source for (int i = 0; i < d->socketNotifierSource->pollfds.count(); ++i) { @@ -386,19 +386,19 @@ QEventDispatcherGlib::~QEventDispatcherGlib() d->socketNotifierSource->pollfds.~QList<GPollFDWithQSocketNotifier *>(); g_source_destroy(&d->socketNotifierSource->source); g_source_unref(&d->socketNotifierSource->source); - d->socketNotifierSource = 0; + d->socketNotifierSource = nullptr; // destroy post event source g_source_destroy(&d->postEventSource->source); g_source_unref(&d->postEventSource->source); - d->postEventSource = 0; + d->postEventSource = nullptr; - Q_ASSERT(d->mainContext != 0); + Q_ASSERT(d->mainContext != nullptr); #if GLIB_CHECK_VERSION (2, 22, 0) g_main_context_pop_thread_default (d->mainContext); #endif g_main_context_unref(d->mainContext); - d->mainContext = 0; + d->mainContext = nullptr; } bool QEventDispatcherGlib::processEvents(QEventLoop::ProcessEventsFlags flags) diff --git a/src/corelib/kernel/qeventdispatcher_unix.cpp b/src/corelib/kernel/qeventdispatcher_unix.cpp index 2492d70005..0165ce9075 100644 --- a/src/corelib/kernel/qeventdispatcher_unix.cpp +++ b/src/corelib/kernel/qeventdispatcher_unix.cpp @@ -465,7 +465,7 @@ bool QEventDispatcherUNIX::processEvents(QEventLoop::ProcessEventsFlags flags) emit awake(); auto threadData = d->threadData.loadRelaxed(); - QCoreApplicationPrivate::sendPostedEvents(0, 0, threadData); + QCoreApplicationPrivate::sendPostedEvents(nullptr, 0, threadData); const bool include_timers = (flags & QEventLoop::X11ExcludeTimers) == 0; const bool include_notifiers = (flags & QEventLoop::ExcludeSocketNotifiers) == 0; diff --git a/src/corelib/kernel/qmetaobject.cpp b/src/corelib/kernel/qmetaobject.cpp index 87cced41f8..3883613d49 100644 --- a/src/corelib/kernel/qmetaobject.cpp +++ b/src/corelib/kernel/qmetaobject.cpp @@ -286,14 +286,14 @@ QObject *QMetaObject::newInstance(QGenericArgument val0, idx = indexOfConstructor(norm.constData()); } if (idx < 0) - return 0; + return nullptr; - QObject *returnValue = 0; + QObject *returnValue = nullptr; void *param[] = {&returnValue, val0.data(), val1.data(), val2.data(), val3.data(), val4.data(), val5.data(), val6.data(), val7.data(), val8.data(), val9.data()}; if (static_metacall(CreateInstance, idx, param) >= 0) - return 0; + return nullptr; return returnValue; } @@ -305,7 +305,7 @@ int QMetaObject::static_metacall(Call cl, int idx, void **argv) const Q_ASSERT(priv(d.data)->revision >= 6); if (!d.static_metacall) return 0; - d.static_metacall(0, cl, idx, argv); + d.static_metacall(nullptr, cl, idx, argv); return -1; } @@ -697,7 +697,7 @@ static void argumentTypesFromString(const char *str, const char *end, QByteArray QMetaObjectPrivate::decodeMethodSignature( const char *signature, QArgumentTypeArray &types) { - Q_ASSERT(signature != 0); + Q_ASSERT(signature != nullptr); const char *lparens = strchr(signature, '('); if (!lparens) return QByteArray(); @@ -850,7 +850,7 @@ int QMetaObjectPrivate::indexOfConstructor(const QMetaObject *m, const QByteArra */ int QMetaObjectPrivate::absoluteSignalCount(const QMetaObject *m) { - Q_ASSERT(m != 0); + Q_ASSERT(m != nullptr); int n = priv(m->d.data)->signalCount; for (m = m->d.superdata; m; m = m->d.superdata) n += priv(m->d.data)->signalCount; @@ -887,7 +887,7 @@ QMetaMethod QMetaObjectPrivate::signal(const QMetaObject *m, int signal_index) QMetaMethod result; if (signal_index < 0) return result; - Q_ASSERT(m != 0); + Q_ASSERT(m != nullptr); int i = signal_index; i -= signalOffset(m); if (i < 0 && m->d.superdata) @@ -1037,7 +1037,7 @@ int QMetaObject::indexOfProperty(const char *name) const QAbstractDynamicMetaObject *me = const_cast<QAbstractDynamicMetaObject *>(static_cast<const QAbstractDynamicMetaObject *>(this)); - return me->createProperty(name, 0); + return me->createProperty(name, nullptr); } return -1; @@ -1151,7 +1151,7 @@ QMetaProperty QMetaObject::property(int index) const if (!result.menum.isValid()) { const char *enum_name = type; const char *scope_name = objectClassName(this); - char *scope_buffer = 0; + char *scope_buffer = nullptr; const char *colon = strrchr(enum_name, ':'); // ':' will always appear in pairs @@ -1165,7 +1165,7 @@ QMetaProperty QMetaObject::property(int index) const enum_name = colon+1; } - const QMetaObject *scope = 0; + const QMetaObject *scope = nullptr; if (qstrcmp(scope_name, "Qt") == 0) scope = &Qt::staticMetaObject; else @@ -1548,14 +1548,14 @@ bool QMetaObject::invokeMethodImpl(QObject *object, QtPrivate::QSlotObjectBase * return false; } - QCoreApplication::postEvent(object, new QMetaCallEvent(slot, 0, -1, 1)); + QCoreApplication::postEvent(object, new QMetaCallEvent(slot, nullptr, -1, 1)); } else if (type == Qt::BlockingQueuedConnection) { #if QT_CONFIG(thread) if (currentThread == objectThread) qWarning("QMetaObject::invokeMethod: Dead lock detected"); QSemaphore semaphore; - QCoreApplication::postEvent(object, new QMetaCallEvent(slot, 0, -1, argv, &semaphore)); + QCoreApplication::postEvent(object, new QMetaCallEvent(slot, nullptr, -1, argv, &semaphore)); semaphore.acquire(); #endif // QT_CONFIG(thread) } else { @@ -1994,7 +1994,7 @@ QList<QByteArray> QMetaMethod::parameterNames() const const char *QMetaMethod::typeName() const { if (!mobj) - return 0; + return nullptr; return QMetaMethodPrivate::get(this)->rawReturnTypeName(); } @@ -2026,7 +2026,7 @@ const char *QMetaMethod::typeName() const const char *QMetaMethod::tag() const { if (!mobj) - return 0; + return nullptr; return QMetaMethodPrivate::get(this)->tag().constData(); } @@ -2309,7 +2309,7 @@ bool QMetaMethod::invoke(QObject *object, return false; } - QScopedPointer<QMetaCallEvent> event(new QMetaCallEvent(idx_offset, idx_relative, callFunction, 0, -1, paramCount)); + QScopedPointer<QMetaCallEvent> event(new QMetaCallEvent(idx_offset, idx_relative, callFunction, nullptr, -1, paramCount)); int *types = event->types(); void **args = event->args(); @@ -2346,7 +2346,7 @@ bool QMetaMethod::invoke(QObject *object, QSemaphore semaphore; QCoreApplication::postEvent(object, new QMetaCallEvent(idx_offset, idx_relative, callFunction, - 0, -1, param, &semaphore)); + nullptr, -1, param, &semaphore)); semaphore.acquire(); #endif // QT_CONFIG(thread) } @@ -2569,7 +2569,7 @@ bool QMetaMethod::invokeOnGadget(void* gadget, QGenericReturnArgument returnValu const char *QMetaEnum::name() const { if (!mobj) - return 0; + return nullptr; return rawStringData(mobj, mobj->d.data[handle]); } @@ -2588,7 +2588,7 @@ const char *QMetaEnum::name() const const char *QMetaEnum::enumName() const { if (!mobj) - return 0; + return nullptr; const bool rev8p = priv(mobj->d.data)->revision >= 8; if (rev8p) return rawStringData(mobj, mobj->d.data[handle + 1]); @@ -2616,13 +2616,13 @@ int QMetaEnum::keyCount() const const char *QMetaEnum::key(int index) const { if (!mobj) - return 0; + return nullptr; const int offset = priv(mobj->d.data)->revision >= 8 ? 3 : 2; int count = mobj->d.data[handle + offset]; int data = mobj->d.data[handle + offset + 1]; if (index >= 0 && index < count) return rawStringData(mobj, mobj->d.data[data + 2*index]); - return 0; + return nullptr; } /*! @@ -2685,7 +2685,7 @@ bool QMetaEnum::isScoped() const */ const char *QMetaEnum::scope() const { - return mobj ? objectClassName(mobj) : 0; + return mobj ? objectClassName(mobj) : nullptr; } /*! @@ -2701,7 +2701,7 @@ const char *QMetaEnum::scope() const */ int QMetaEnum::keyToValue(const char *key, bool *ok) const { - if (ok != 0) + if (ok != nullptr) *ok = false; if (!mobj || !key) return -1; @@ -2721,7 +2721,7 @@ int QMetaEnum::keyToValue(const char *key, bool *ok) const const QByteArray className = stringData(mobj, priv(mobj->d.data)->className); if ((!scope || (className.size() == int(scope) && strncmp(qualified_key, className.constData(), scope) == 0)) && strcmp(key, rawStringData(mobj, mobj->d.data[data + 2*i])) == 0) { - if (ok != 0) + if (ok != nullptr) *ok = true; return mobj->d.data[data + 2*i + 1]; } @@ -2740,14 +2740,14 @@ int QMetaEnum::keyToValue(const char *key, bool *ok) const const char* QMetaEnum::valueToKey(int value) const { if (!mobj) - return 0; + return nullptr; const int offset = priv(mobj->d.data)->revision >= 8 ? 3 : 2; int count = mobj->d.data[handle + offset]; int data = mobj->d.data[handle + offset + 1]; for (int i = 0; i < count; ++i) if (value == (int)mobj->d.data[data + 2*i + 1]) return rawStringData(mobj, mobj->d.data[data + 2*i]); - return 0; + return nullptr; } /*! @@ -2762,11 +2762,11 @@ const char* QMetaEnum::valueToKey(int value) const */ int QMetaEnum::keysToValue(const char *keys, bool *ok) const { - if (ok != 0) + if (ok != nullptr) *ok = false; if (!mobj || !keys) return -1; - if (ok != 0) + if (ok != nullptr) *ok = true; const QString keysString = QString::fromLatin1(keys); const QVector<QStringRef> splitKeys = keysString.splitRef(QLatin1Char('|')); @@ -2799,7 +2799,7 @@ int QMetaEnum::keysToValue(const char *keys, bool *ok) const } } if (i < 0) { - if (ok != 0) + if (ok != nullptr) *ok = false; value |= -1; } @@ -2902,7 +2902,7 @@ static QByteArray qualifiedName(const QMetaEnum &e) \internal */ QMetaProperty::QMetaProperty() - : mobj(0), handle(0), idx(0) + : mobj(nullptr), handle(0), idx(0) { } @@ -2915,7 +2915,7 @@ QMetaProperty::QMetaProperty() const char *QMetaProperty::name() const { if (!mobj) - return 0; + return nullptr; int handle = priv(mobj->d.data)->propertyData + 3*idx; return rawStringData(mobj, mobj->d.data[handle]); } @@ -2928,7 +2928,7 @@ const char *QMetaProperty::name() const const char *QMetaProperty::typeName() const { if (!mobj) - return 0; + return nullptr; int handle = priv(mobj->d.data)->propertyData + 3*idx; return rawTypeNameFromTypeInfo(mobj, mobj->d.data[handle + 1]); } @@ -3118,7 +3118,7 @@ QVariant QMetaProperty::read(const QObject *object) const t = enumMetaTypeId; } else { int handle = priv(mobj->d.data)->propertyData + 3*idx; - const char *typeName = 0; + const char *typeName = nullptr; Q_ASSERT(priv(mobj->d.data)->revision >= 7); uint typeInfo = mobj->d.data[handle + 1]; if (!(typeInfo & IsUnresolvedType)) @@ -3144,11 +3144,11 @@ QVariant QMetaProperty::read(const QObject *object) const // changed: result stored directly in value int status = -1; QVariant value; - void *argv[] = { 0, &value, &status }; + void *argv[] = { nullptr, &value, &status }; if (t == QMetaType::QVariant) { argv[0] = &value; } else { - value = QVariant(t, (void*)0); + value = QVariant(t, (void*)nullptr); argv[0] = value.data(); } if (priv(mobj->d.data)->flags & PropertyAccessInStaticMetaCall && mobj->d.static_metacall) { @@ -3202,7 +3202,7 @@ bool QMetaProperty::write(QObject *object, const QVariant &value) const v.convert(QVariant::Int); } else { int handle = priv(mobj->d.data)->propertyData + 3*idx; - const char *typeName = 0; + const char *typeName = nullptr; Q_ASSERT(priv(mobj->d.data)->revision >= 7); uint typeInfo = mobj->d.data[handle + 1]; if (!(typeInfo & IsUnresolvedType)) @@ -3219,7 +3219,7 @@ bool QMetaProperty::write(QObject *object, const QVariant &value) const if (!value.isValid()) { if (isResettable()) return reset(object); - v = QVariant(t, 0); + v = QVariant(t, nullptr); } else if (!v.convert(t)) { return false; } @@ -3235,7 +3235,7 @@ bool QMetaProperty::write(QObject *object, const QVariant &value) const // the flags variable is used by the declarative module to implement // interception of property writes. int flags = 0; - void *argv[] = { 0, &v, &status, &flags }; + void *argv[] = { nullptr, &v, &status, &flags }; if (t == QMetaType::QVariant) argv[0] = &v; else @@ -3260,7 +3260,7 @@ bool QMetaProperty::reset(QObject *object) const { if (!object || !mobj || !isResettable()) return false; - void *argv[] = { 0 }; + void *argv[] = { nullptr }; if (priv(mobj->d.data)->flags & PropertyAccessInStaticMetaCall && mobj->d.static_metacall) mobj->d.static_metacall(object, QMetaObject::ResetProperty, idx, argv); else @@ -3644,7 +3644,7 @@ bool QMetaProperty::isEditable(const QObject *object) const const char *QMetaClassInfo::name() const { if (!mobj) - return 0; + return nullptr; return rawStringData(mobj, mobj->d.data[handle]); } @@ -3656,7 +3656,7 @@ const char *QMetaClassInfo::name() const const char* QMetaClassInfo::value() const { if (!mobj) - return 0; + return nullptr; return rawStringData(mobj, mobj->d.data[handle + 1]); } diff --git a/src/corelib/kernel/qmetaobjectbuilder.cpp b/src/corelib/kernel/qmetaobjectbuilder.cpp index 2487681f78..d02708540a 100644 --- a/src/corelib/kernel/qmetaobjectbuilder.cpp +++ b/src/corelib/kernel/qmetaobjectbuilder.cpp @@ -210,7 +210,7 @@ public: : flags(0) { superClass = &QObject::staticMetaObject; - staticMetacallFunction = 0; + staticMetacallFunction = nullptr; } bool hasRevisionedProperties() const; @@ -749,7 +749,7 @@ void QMetaObjectBuilder::addMetaObject Q_ASSERT(priv(prototype->d.data)->revision >= 2); const auto *objects = prototype->d.relatedMetaObjects; if (objects) { - while (*objects != 0) { + while (*objects != nullptr) { addRelatedMetaObject(*objects); ++objects; } @@ -831,7 +831,7 @@ const QMetaObject *QMetaObjectBuilder::relatedMetaObject(int index) const if (index >= 0 && index < d->relatedMetaObjects.size()) return d->relatedMetaObjects[index]; else - return 0; + return nullptr; } /*! @@ -1194,8 +1194,8 @@ static int buildMetaObject(QMetaObjectBuilderPrivate *d, char *buf, ALIGN(size, int); if (buf) { if (!relocatable) meta->d.superdata = d->superClass; - meta->d.relatedMetaObjects = 0; - meta->d.extradata = 0; + meta->d.relatedMetaObjects = nullptr; + meta->d.extradata = nullptr; meta->d.static_metacall = d->staticMetacallFunction; } @@ -1492,7 +1492,7 @@ static int buildMetaObject(QMetaObjectBuilderPrivate *d, char *buf, */ QMetaObject *QMetaObjectBuilder::toMetaObject() const { - int size = buildMetaObject(d, 0, 0, false); + int size = buildMetaObject(d, nullptr, 0, false); char *buf = reinterpret_cast<char *>(malloc(size)); memset(buf, 0, size); buildMetaObject(d, buf, size, false); @@ -1515,7 +1515,7 @@ QMetaObject *QMetaObjectBuilder::toMetaObject() const */ QByteArray QMetaObjectBuilder::toRelocatableData(bool *ok) const { - int size = buildMetaObject(d, 0, 0, true); + int size = buildMetaObject(d, nullptr, 0, true); if (size == -1) { if (ok) *ok = false; return QByteArray(); @@ -1553,9 +1553,9 @@ void QMetaObjectBuilder::fromRelocatableData(QMetaObject *output, output->d.superdata = superclass; output->d.stringdata = reinterpret_cast<const uint *>(buf + stringdataOffset); output->d.data = reinterpret_cast<const uint *>(buf + dataOffset); - output->d.extradata = 0; - output->d.relatedMetaObjects = 0; - output->d.static_metacall = 0; + output->d.extradata = nullptr; + output->d.relatedMetaObjects = nullptr; + output->d.static_metacall = nullptr; } /*! @@ -1718,14 +1718,14 @@ void QMetaObjectBuilder::deserialize d->enumerators.clear(); d->constructors.clear(); d->relatedMetaObjects.clear(); - d->staticMetacallFunction = 0; + d->staticMetacallFunction = nullptr; // Read the class and super class names. stream >> d->className; stream >> name; if (name.isEmpty()) { - d->superClass = 0; - } else if ((cl = resolveClassName(references, name)) != 0) { + d->superClass = nullptr; + } else if ((cl = resolveClassName(references, name)) != nullptr) { d->superClass = cl; } else { stream.setStatus(QDataStream::ReadCorruptData); @@ -1875,7 +1875,7 @@ QMetaMethodBuilderPrivate *QMetaMethodBuilder::d_func() const else if (_mobj && -_index >= 1 && -_index <= int(_mobj->d->constructors.size())) return &(_mobj->d->constructors[(-_index) - 1]); else - return 0; + return nullptr; } /*! @@ -2114,7 +2114,7 @@ QMetaPropertyBuilderPrivate *QMetaPropertyBuilder::d_func() const if (_mobj && _index >= 0 && _index < int(_mobj->d->properties.size())) return &(_mobj->d->properties[_index]); else - return 0; + return nullptr; } /*! @@ -2586,7 +2586,7 @@ QMetaEnumBuilderPrivate *QMetaEnumBuilder::d_func() const if (_mobj && _index >= 0 && _index < int(_mobj->d->enumerators.size())) return &(_mobj->d->enumerators[_index]); else - return 0; + return nullptr; } /*! diff --git a/src/corelib/kernel/qmetatype.cpp b/src/corelib/kernel/qmetatype.cpp index 5c1e4b4ddd..89765fb11a 100644 --- a/src/corelib/kernel/qmetatype.cpp +++ b/src/corelib/kernel/qmetatype.cpp @@ -508,6 +508,31 @@ struct DefinedTypesFilter { Destructs this object. */ +/*! + \fn template<typename T> QMetaType QMetaType::fromType() + \since 5.15 + + Returns the QMetaType corresponding to the type in the template parameter. +*/ + +/*! \fn bool operator==(const QMetaType &a, const QMetaType &b) + \since 5.15 + \relates QMetaType + \overload + + Returns \c true if the QMetaType \a a represents the same type + as the QMetaType \a b, otherwise returns \c false. +*/ + +/*! \fn bool operator!=(const QMetaType &a, const QMetaType &c) + \since 5.15 + \relates QMetaType + \overload + + Returns \c true if the QMetaType \a a represents a difference type + than the QMetaType \a b, otherwise returns \c false. +*/ + #define QT_ADD_STATIC_METATYPE(MetaTypeName, MetaTypeId, RealName) \ { #RealName, sizeof(#RealName) - 1, MetaTypeId }, @@ -932,7 +957,7 @@ constexpr MetaTypeOffsets<QtPrivate::Indexes<QMetaType::HighestInternalId + 1>:: pointer if no matching type was found. The returned pointer must not be deleted. - \sa type(), isRegistered(), Type + \sa type(), isRegistered(), Type, name() */ const char *QMetaType::typeName(int typeId) { @@ -952,6 +977,20 @@ const char *QMetaType::typeName(int typeId) #undef QT_METATYPE_TYPEID_TYPENAME_CONVERTER } +/*! + \since 5.15 + + Returns the type name associated with this QMetaType, or a null + pointer if no matching type was found. The returned pointer must not be + deleted. + + \sa typeName() +*/ +QByteArray QMetaType::name() const +{ + return QMetaType::typeName(m_typeId); +} + /* Similar to QMetaType::type(), but only looks in the static set of types. */ @@ -1115,8 +1154,8 @@ static int registerNormalizedType(const NS(QByteArray) &normalizedTypeName, QCustomTypeInfo inf; inf.typeName = normalizedTypeName; #ifndef QT_NO_DATASTREAM - inf.loadOp = 0; - inf.saveOp = 0; + inf.loadOp = nullptr; + inf.saveOp = nullptr; #endif inf.alias = -1; inf.typedConstructor = typedConstructor; @@ -1957,7 +1996,7 @@ public: return Q_LIKELY(qMetaTypeWidgetsHelper) ? qMetaTypeWidgetsHelper[type - QMetaType::FirstWidgetsType].metaObject : nullptr; - return 0; + return nullptr; } }; @@ -2216,6 +2255,8 @@ QMetaType QMetaType::typeInfo(const int type) \since 5.0 Constructs a QMetaType object that contains all information about type \a typeId. + + \note: The default parameter was added in Qt 5.15 */ QMetaType::QMetaType(const int typeId) : m_typeId(typeId) diff --git a/src/corelib/kernel/qmetatype.h b/src/corelib/kernel/qmetatype.h index af1b0faf38..ee7c0fa4a4 100644 --- a/src/corelib/kernel/qmetatype.h +++ b/src/corelib/kernel/qmetatype.h @@ -579,7 +579,7 @@ public: static bool load(QDataStream &stream, int type, void *data); #endif - explicit QMetaType(const int type); // ### Qt6: drop const + explicit QMetaType(const int type = QMetaType::UnknownType); // ### Qt6: drop const inline ~QMetaType(); inline bool isValid() const; @@ -588,12 +588,24 @@ public: inline int sizeOf() const; inline TypeFlags flags() const; inline const QMetaObject *metaObject() const; + QT_PREPEND_NAMESPACE(QByteArray) name() const; inline void *create(const void *copy = nullptr) const; inline void destroy(void *data) const; inline void *construct(void *where, const void *copy = nullptr) const; inline void destruct(void *data) const; + template<typename T> + static QMetaType fromType() + { return QMetaType(qMetaTypeId<T>()); } + + friend bool operator==(const QMetaType &a, const QMetaType &b) + { return a.m_typeId == b.m_typeId; } + + friend bool operator!=(const QMetaType &a, const QMetaType &b) + { return a.m_typeId != b.m_typeId; } + + public: template<typename T> static bool registerComparators() diff --git a/src/corelib/kernel/qmimedata.cpp b/src/corelib/kernel/qmimedata.cpp index 9a98db21d3..00e5183eb1 100644 --- a/src/corelib/kernel/qmimedata.cpp +++ b/src/corelib/kernel/qmimedata.cpp @@ -319,7 +319,7 @@ QVariant QMimeDataPrivate::retrieveTypedData(const QString &format, QVariant::Ty Constructs a new MIME data object with no data in it. */ QMimeData::QMimeData() - : QObject(*new QMimeDataPrivate, 0) + : QObject(*new QMimeDataPrivate, nullptr) { } diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp index a2f76a6354..304491844b 100644 --- a/src/corelib/kernel/qobject.cpp +++ b/src/corelib/kernel/qobject.cpp @@ -109,7 +109,7 @@ static int *queuedConnectionTypes(const QList<QByteArray> &typeNames) "(Make sure '%s' is registered using qRegisterMetaType().)", typeName.constData(), typeName.constData()); delete [] types; - return 0; + return nullptr; } } types[typeNames.count()] = 0; @@ -133,7 +133,7 @@ static int *queuedConnectionTypes(const QArgumentType *argumentTypes, int argc) qWarning("QObject::connect: Cannot queue arguments of type '%s'\n" "(Make sure '%s' is registered using qRegisterMetaType().)", type.name().constData(), type.name().constData()); - return 0; + return nullptr; } } types[argc] = 0; @@ -160,12 +160,12 @@ extern "C" Q_CORE_EXPORT void qt_removeObject(QObject *) {} #endif -void (*QAbstractDeclarativeData::destroyed)(QAbstractDeclarativeData *, QObject *) = 0; -void (*QAbstractDeclarativeData::parentChanged)(QAbstractDeclarativeData *, QObject *, QObject *) = 0; -void (*QAbstractDeclarativeData::signalEmitted)(QAbstractDeclarativeData *, QObject *, int, void **) = 0; -int (*QAbstractDeclarativeData::receivers)(QAbstractDeclarativeData *, const QObject *, int) = 0; -bool (*QAbstractDeclarativeData::isSignalConnected)(QAbstractDeclarativeData *, const QObject *, int) = 0; -void (*QAbstractDeclarativeData::setWidgetParent)(QObject *, QObject *) = 0; +void (*QAbstractDeclarativeData::destroyed)(QAbstractDeclarativeData *, QObject *) = nullptr; +void (*QAbstractDeclarativeData::parentChanged)(QAbstractDeclarativeData *, QObject *, QObject *) = nullptr; +void (*QAbstractDeclarativeData::signalEmitted)(QAbstractDeclarativeData *, QObject *, int, void **) = nullptr; +int (*QAbstractDeclarativeData::receivers)(QAbstractDeclarativeData *, const QObject *, int) = nullptr; +bool (*QAbstractDeclarativeData::isSignalConnected)(QAbstractDeclarativeData *, const QObject *, int) = nullptr; +void (*QAbstractDeclarativeData::setWidgetParent)(QObject *, QObject *) = nullptr; /*! \fn QObjectData::QObjectData() @@ -181,7 +181,7 @@ QMetaObject *QObjectData::dynamicMetaObject() const } QObjectPrivate::QObjectPrivate(int version) - : threadData(0), currentChildBeingDeleted(0) + : threadData(nullptr), currentChildBeingDeleted(nullptr) { #ifdef QT_BUILD_INTERNAL // Don't check the version parameter in internal builds. @@ -194,8 +194,8 @@ QObjectPrivate::QObjectPrivate(int version) #endif // QObjectData initialization - q_ptr = 0; - parent = 0; // no parent yet. It is set by setParent() + q_ptr = nullptr; + parent = nullptr; // no parent yet. It is set by setParent() isWidget = false; // assume not a widget object blockSig = false; // not blocking signals wasDeleted = false; // double-delete catcher @@ -203,8 +203,8 @@ QObjectPrivate::QObjectPrivate(int version) sendChildEvents = true; // if we should send ChildAdded and ChildRemoved events to parent receiveChildEvents = true; postedEvents = 0; - extraData = 0; - metaObject = 0; + extraData = nullptr; + metaObject = nullptr; isWindow = false; deleteLaterCalled = false; } @@ -921,8 +921,8 @@ QObject::QObject(QObjectPrivate &dd, QObject *parent) d->threadData.storeRelaxed(threadData); if (parent) { QT_TRY { - if (!check_parent_thread(parent, parent ? parent->d_func()->threadData.loadRelaxed() : 0, threadData)) - parent = 0; + if (!check_parent_thread(parent, parent ? parent->d_func()->threadData.loadRelaxed() : nullptr, threadData)) + parent = nullptr; if (d->isWidget) { if (parent) { d->parent = parent; @@ -1083,7 +1083,7 @@ QObject::~QObject() Q_TRACE(QObject_dtor, this); if (d->parent) // remove it from parent object - d->setParent_helper(0); + d->setParent_helper(nullptr); } QObjectPrivate::Connection::~Connection() @@ -1529,7 +1529,7 @@ void QObject::moveToThread(QThread *targetThread) return; } - if (d->parent != 0) { + if (d->parent != nullptr) { qWarning("QObject::moveToThread: Cannot move objects with a parent"); return; } @@ -1606,7 +1606,7 @@ void QObjectPrivate::setThreadData_helper(QThreadData *currentData, QThreadData if (pe.receiver == q) { // move this post event to the targetList targetData->postEventList.addEvent(pe); - const_cast<QPostEvent &>(pe).event = 0; + const_cast<QPostEvent &>(pe).event = nullptr; ++eventsMoved; } } @@ -2053,7 +2053,7 @@ void qt_qFindChildren_helper(const QObject *parent, const QRegularExpression &re QObject *qt_qFindChild_helper(const QObject *parent, const QString &name, const QMetaObject &mo, Qt::FindChildOptions options) { if (!parent) - return 0; + return nullptr; const QObjectList &children = parent->children(); QObject *obj; int i; @@ -2069,7 +2069,7 @@ QObject *qt_qFindChild_helper(const QObject *parent, const QString &name, const return obj; } } - return 0; + return nullptr; } /*! @@ -2097,7 +2097,7 @@ void QObjectPrivate::deleteChildren() delete currentChildBeingDeleted; } children.clear(); - currentChildBeingDeleted = 0; + currentChildBeingDeleted = nullptr; isDeletingChildren = false; } @@ -2149,7 +2149,7 @@ void QObjectPrivate::setParent_helper(QObject *o) // object hierarchies are constrained to a single thread if (threadData != parent->d_func()->threadData) { qWarning("QObject::setParent: Cannot set parent, new parent is in a different thread"); - parent = 0; + parent = nullptr; return; } parent->d_func()->children.append(q); @@ -2220,7 +2220,7 @@ void QObject::installEventFilter(QObject *obj) d->extraData = new QObjectPrivate::ExtraData; // clean up unused items in the list - d->extraData->eventFilters.removeAll((QObject*)0); + d->extraData->eventFilters.removeAll((QObject*)nullptr); d->extraData->eventFilters.removeAll(obj); d->extraData->eventFilters.prepend(obj); } @@ -2244,7 +2244,7 @@ void QObject::removeEventFilter(QObject *obj) if (d->extraData) { for (int i = 0; i < d->extraData->eventFilters.count(); ++i) { if (d->extraData->eventFilters.at(i) == obj) - d->extraData->eventFilters[i] = 0; + d->extraData->eventFilters[i] = nullptr; } } } @@ -2367,7 +2367,7 @@ void QObject::deleteLater() const char *qFlagLocation(const char *method) { QThreadData *currentThreadData = QThreadData::current(false); - if (currentThreadData != 0) + if (currentThreadData != nullptr) currentThreadData->flaggedSignatures.store(method); return method; } @@ -2386,7 +2386,7 @@ static const char * extract_location(const char *member) if (*location != '\0') return location; } - return 0; + return nullptr; } static bool check_signal_macro(const QObject *sender, const char *signal, @@ -2425,7 +2425,7 @@ static void err_method_notfound(const QObject *object, case QSIGNAL_CODE: type = "signal"; break; } const char *loc = extract_location(method); - if (strchr(method,')') == 0) // common typing mistake + if (strchr(method,')') == nullptr) // common typing mistake qWarning("QObject::%s: Parentheses expected, %s %s::%s%s%s", func, type, object->metaObject()->className(), method+1, loc ? " in ": "", loc ? loc : ""); @@ -2485,7 +2485,7 @@ QObject *QObject::sender() const return cd->currentSender->sender; } - return 0; + return nullptr; } /*! @@ -2664,7 +2664,7 @@ void QMetaObjectPrivate::memberIndexes(const QObject *obj, return; const QMetaObject *m = obj->metaObject(); // Check that member is member of obj class - while (m != 0 && m != member.mobj) + while (m != nullptr && m != member.mobj) m = m->d.superdata; if (!m) return; @@ -2775,18 +2775,18 @@ QMetaObject::Connection QObject::connect(const QObject *sender, const char *sign const QObject *receiver, const char *method, Qt::ConnectionType type) { - if (sender == 0 || receiver == 0 || signal == 0 || method == 0) { + if (sender == nullptr || receiver == nullptr || signal == nullptr || method == nullptr) { qWarning("QObject::connect: Cannot connect %s::%s to %s::%s", sender ? sender->metaObject()->className() : "(null)", (signal && *signal) ? signal+1 : "(null)", receiver ? receiver->metaObject()->className() : "(null)", (method && *method) ? method+1 : "(null)"); - return QMetaObject::Connection(0); + return QMetaObject::Connection(nullptr); } QByteArray tmp_signal_name; if (!check_signal_macro(sender, signal, "connect", "bind")) - return QMetaObject::Connection(0); + return QMetaObject::Connection(nullptr); const QMetaObject *smeta = sender->metaObject(); const char *signal_arg = signal; ++signal; //skip code @@ -2809,7 +2809,7 @@ QMetaObject::Connection QObject::connect(const QObject *sender, const char *sign if (signal_index < 0) { err_method_notfound(sender, signal_arg, "connect"); err_info_about_objects("connect", sender, receiver); - return QMetaObject::Connection(0); + return QMetaObject::Connection(nullptr); } signal_index = QMetaObjectPrivate::originalClone(smeta, signal_index); signal_index += QMetaObjectPrivate::signalOffset(smeta); @@ -2818,7 +2818,7 @@ QMetaObject::Connection QObject::connect(const QObject *sender, const char *sign int membcode = extract_code(method); if (!check_method_code(membcode, receiver, method, "connect")) - return QMetaObject::Connection(0); + return QMetaObject::Connection(nullptr); const char *method_arg = method; ++method; // skip code @@ -2861,7 +2861,7 @@ QMetaObject::Connection QObject::connect(const QObject *sender, const char *sign if (method_index_relative < 0) { err_method_notfound(receiver, method_arg, "connect"); err_info_about_objects("connect", sender, receiver); - return QMetaObject::Connection(0); + return QMetaObject::Connection(nullptr); } if (!QMetaObjectPrivate::checkConnectArgs(signalTypes.size(), signalTypes.constData(), @@ -2870,13 +2870,13 @@ QMetaObject::Connection QObject::connect(const QObject *sender, const char *sign "\n %s::%s --> %s::%s", sender->metaObject()->className(), signal, receiver->metaObject()->className(), method); - return QMetaObject::Connection(0); + return QMetaObject::Connection(nullptr); } - int *types = 0; + int *types = nullptr; if ((type == Qt::QueuedConnection) && !(types = queuedConnectionTypes(signalTypes.constData(), signalTypes.size()))) { - return QMetaObject::Connection(0); + return QMetaObject::Connection(nullptr); } #ifndef QT_NO_DEBUG @@ -2913,8 +2913,8 @@ QMetaObject::Connection QObject::connect(const QObject *sender, const QMetaMetho const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type) { - if (sender == 0 - || receiver == 0 + if (sender == nullptr + || receiver == nullptr || signal.methodType() != QMetaMethod::Signal || method.methodType() == QMetaMethod::Constructor) { qWarning("QObject::connect: Cannot connect %s::%s to %s::%s", @@ -2922,7 +2922,7 @@ QMetaObject::Connection QObject::connect(const QObject *sender, const QMetaMetho signal.methodSignature().constData(), receiver ? receiver->metaObject()->className() : "(null)", method.methodSignature().constData() ); - return QMetaObject::Connection(0); + return QMetaObject::Connection(nullptr); } int signal_index; @@ -2938,12 +2938,12 @@ QMetaObject::Connection QObject::connect(const QObject *sender, const QMetaMetho if (signal_index == -1) { qWarning("QObject::connect: Can't find signal %s on instance of class %s", signal.methodSignature().constData(), smeta->className()); - return QMetaObject::Connection(0); + return QMetaObject::Connection(nullptr); } if (method_index == -1) { qWarning("QObject::connect: Can't find method %s on instance of class %s", method.methodSignature().constData(), rmeta->className()); - return QMetaObject::Connection(0); + return QMetaObject::Connection(nullptr); } if (!QMetaObject::checkConnectArgs(signal.methodSignature().constData(), method.methodSignature().constData())) { @@ -2951,19 +2951,19 @@ QMetaObject::Connection QObject::connect(const QObject *sender, const QMetaMetho "\n %s::%s --> %s::%s", smeta->className(), signal.methodSignature().constData(), rmeta->className(), method.methodSignature().constData()); - return QMetaObject::Connection(0); + return QMetaObject::Connection(nullptr); } - int *types = 0; + int *types = nullptr; if ((type == Qt::QueuedConnection) && !(types = queuedConnectionTypes(signal.parameterTypes()))) - return QMetaObject::Connection(0); + return QMetaObject::Connection(nullptr); #ifndef QT_NO_DEBUG check_and_warn_compat(smeta, signal, rmeta, method); #endif QMetaObject::Connection handle = QMetaObject::Connection(QMetaObjectPrivate::connect( - sender, signal_index, signal.enclosingMetaObject(), receiver, method_index, 0, type, types)); + sender, signal_index, signal.enclosingMetaObject(), receiver, method_index, nullptr, type, types)); return handle; } @@ -3046,7 +3046,7 @@ QMetaObject::Connection QObject::connect(const QObject *sender, const QMetaMetho bool QObject::disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method) { - if (sender == 0 || (receiver == 0 && method != 0)) { + if (sender == nullptr || (receiver == nullptr && method != nullptr)) { qWarning("QObject::disconnect: Unexpected null parameter"); return false; } @@ -3118,7 +3118,7 @@ bool QObject::disconnect(const QObject *sender, const char *signal, } if (!method) { - res |= QMetaObjectPrivate::disconnect(sender, signal_index, smeta, receiver, -1, 0); + res |= QMetaObjectPrivate::disconnect(sender, signal_index, smeta, receiver, -1, nullptr); } else { const QMetaObject *rmeta = receiver->metaObject(); do { @@ -3129,7 +3129,7 @@ bool QObject::disconnect(const QObject *sender, const char *signal, rmeta = rmeta->superClass(); if (method_index < 0) break; - res |= QMetaObjectPrivate::disconnect(sender, signal_index, smeta, receiver, method_index, 0); + res |= QMetaObjectPrivate::disconnect(sender, signal_index, smeta, receiver, method_index, nullptr); method_found = true; } while ((rmeta = rmeta->superClass())); } @@ -3181,7 +3181,7 @@ bool QObject::disconnect(const QObject *sender, const char *signal, bool QObject::disconnect(const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method) { - if (sender == 0 || (receiver == 0 && method.mobj != 0)) { + if (sender == nullptr || (receiver == nullptr && method.mobj != nullptr)) { qWarning("QObject::disconnect: Unexpected null parameter"); return false; } @@ -3230,7 +3230,7 @@ bool QObject::disconnect(const QObject *sender, const QMetaMethod &signal, return false; } - if (!QMetaObjectPrivate::disconnect(sender, signal_index, signal.mobj, receiver, method_index, 0)) + if (!QMetaObjectPrivate::disconnect(sender, signal_index, signal.mobj, receiver, method_index, nullptr)) return false; if (!signal.isValid()) { @@ -3369,7 +3369,7 @@ QMetaObject::Connection QMetaObject::connect(const QObject *sender, int signal_i signal_index = methodIndexToSignalIndex(&smeta, signal_index); return Connection(QMetaObjectPrivate::connect(sender, signal_index, smeta, receiver, method_index, - 0, //FIXME, we could speed this connection up by computing the relative index + nullptr, //FIXME, we could speed this connection up by computing the relative index type, types)); } @@ -3445,7 +3445,7 @@ bool QMetaObject::disconnect(const QObject *sender, int signal_index, const QMetaObject *smeta = sender->metaObject(); signal_index = methodIndexToSignalIndex(&smeta, signal_index); return QMetaObjectPrivate::disconnect(sender, signal_index, smeta, - receiver, method_index, 0); + receiver, method_index, nullptr); } /*! @@ -3461,7 +3461,7 @@ bool QMetaObject::disconnectOne(const QObject *sender, int signal_index, const QMetaObject *smeta = sender->metaObject(); signal_index = methodIndexToSignalIndex(&smeta, signal_index); return QMetaObjectPrivate::disconnect(sender, signal_index, smeta, - receiver, method_index, 0, + receiver, method_index, nullptr, QMetaObjectPrivate::DisconnectOne); } @@ -3670,7 +3670,7 @@ static void queued_activate(QObject *sender, int signal, QObjectPrivate::Connect argumentTypes = queuedConnectionTypes(m.parameterTypes()); if (!argumentTypes) // cannot queue arguments argumentTypes = &DIRECT_CONNECTION_ONLY; - if (!c->argumentTypes.testAndSetOrdered(0, argumentTypes)) { + if (!c->argumentTypes.testAndSetOrdered(nullptr, argumentTypes)) { if (argumentTypes != &DIRECT_CONNECTION_ONLY) delete [] argumentTypes; argumentTypes = c->argumentTypes.loadRelaxed(); @@ -4888,7 +4888,7 @@ QMetaObject::Connection QObject::connectImpl(const QObject *sender, void **signa if (!senderMetaObject) { qWarning("QObject::connect: signal not found in %s", sender->metaObject()->className()); slotObj->destroyIfLastRef(); - return QMetaObject::Connection(0); + return QMetaObject::Connection(nullptr); } signal_index += QMetaObjectPrivate::signalOffset(senderMetaObject); return QObjectPrivate::connectImpl(sender, signal_index, receiver, slot, slotObj, type, types, senderMetaObject); @@ -5074,7 +5074,7 @@ bool QObject::disconnect(const QMetaObject::Connection &connection) bool QObject::disconnectImpl(const QObject *sender, void **signal, const QObject *receiver, void **slot, const QMetaObject *senderMetaObject) { - if (sender == 0 || (receiver == 0 && slot != 0)) { + if (sender == nullptr || (receiver == nullptr && slot != nullptr)) { qWarning("QObject::disconnect: Unexpected null parameter"); return false; } @@ -5114,7 +5114,7 @@ QMetaObject::Connection QObjectPrivate::connect(const QObject *sender, int signa const QMetaObject *senderMetaObject = sender->metaObject(); signal_index = methodIndexToSignalIndex(&senderMetaObject, signal_index); - return QObjectPrivate::connectImpl(sender, signal_index, sender, /*slot*/0, slotObj, type, /*types*/0, senderMetaObject); + return QObjectPrivate::connectImpl(sender, signal_index, sender, /*slot*/nullptr, slotObj, type, /*types*/nullptr, senderMetaObject); } /*! @@ -5171,7 +5171,7 @@ QMetaObject::Connection& QMetaObject::Connection::operator=(const QMetaObject::C Creates a Connection instance. */ -QMetaObject::Connection::Connection() : d_ptr(0) {} +QMetaObject::Connection::Connection() : d_ptr(nullptr) {} /*! Destructor for QMetaObject::Connection. diff --git a/src/corelib/kernel/qobjectcleanuphandler.cpp b/src/corelib/kernel/qobjectcleanuphandler.cpp index b6c62af4b3..8bf0e1fcab 100644 --- a/src/corelib/kernel/qobjectcleanuphandler.cpp +++ b/src/corelib/kernel/qobjectcleanuphandler.cpp @@ -94,7 +94,7 @@ QObjectCleanupHandler::~QObjectCleanupHandler() QObject *QObjectCleanupHandler::add(QObject* object) { if (!object) - return 0; + return nullptr; connect(object, SIGNAL(destroyed(QObject*)), this, SLOT(objectDestroyed(QObject*))); cleanupObjects.insert(0, object); diff --git a/src/corelib/kernel/qsharedmemory.cpp b/src/corelib/kernel/qsharedmemory.cpp index 39f3002394..2d65e0bbe4 100644 --- a/src/corelib/kernel/qsharedmemory.cpp +++ b/src/corelib/kernel/qsharedmemory.cpp @@ -441,7 +441,7 @@ bool QSharedMemory::attach(AccessMode mode) bool QSharedMemory::isAttached() const { Q_D(const QSharedMemory); - return (0 != d->memory); + return (nullptr != d->memory); } /*! diff --git a/src/corelib/kernel/qsharedmemory_systemv.cpp b/src/corelib/kernel/qsharedmemory_systemv.cpp index fea4a65b5c..0ba5f65641 100644 --- a/src/corelib/kernel/qsharedmemory_systemv.cpp +++ b/src/corelib/kernel/qsharedmemory_systemv.cpp @@ -182,9 +182,9 @@ bool QSharedMemoryPrivate::attach(QSharedMemory::AccessMode mode) } // grab the memory - memory = shmat(id, 0, (mode == QSharedMemory::ReadOnly ? SHM_RDONLY : 0)); + memory = shmat(id, nullptr, (mode == QSharedMemory::ReadOnly ? SHM_RDONLY : 0)); if ((void*) - 1 == memory) { - memory = 0; + memory = nullptr; setErrorString(QLatin1String("QSharedMemory::attach (shmat)")); return false; } @@ -216,7 +216,7 @@ bool QSharedMemoryPrivate::detach() } return false; } - memory = 0; + memory = nullptr; size = 0; // Get the number of current attachments diff --git a/src/corelib/kernel/qsharedmemory_unix.cpp b/src/corelib/kernel/qsharedmemory_unix.cpp index f6d7e78441..bc0f3b03ca 100644 --- a/src/corelib/kernel/qsharedmemory_unix.cpp +++ b/src/corelib/kernel/qsharedmemory_unix.cpp @@ -68,7 +68,7 @@ QSharedMemoryPrivate::QSharedMemoryPrivate() : #ifndef QT_NO_QOBJECT QObjectPrivate(), #endif - memory(0), size(0), error(QSharedMemory::NoError), + memory(nullptr), size(0), error(QSharedMemory::NoError), #ifndef QT_NO_SYSTEMSEMAPHORE systemSemaphore(QString()), lockedByMe(false), #endif diff --git a/src/corelib/kernel/qtestsupport_core.cpp b/src/corelib/kernel/qtestsupport_core.cpp index 7bd81ed498..8498f7f025 100644 --- a/src/corelib/kernel/qtestsupport_core.cpp +++ b/src/corelib/kernel/qtestsupport_core.cpp @@ -55,7 +55,7 @@ Q_CORE_EXPORT void QTestPrivate::qSleep(int ms) Sleep(uint(ms)); #else struct timespec ts = { time_t(ms / 1000), (ms % 1000) * 1000 * 1000 }; - nanosleep(&ts, NULL); + nanosleep(&ts, nullptr); #endif } diff --git a/src/corelib/kernel/qtimer.cpp b/src/corelib/kernel/qtimer.cpp index 948f697dc5..f843fc4236 100644 --- a/src/corelib/kernel/qtimer.cpp +++ b/src/corelib/kernel/qtimer.cpp @@ -277,7 +277,7 @@ protected: }; QSingleShotTimer::QSingleShotTimer(int msec, Qt::TimerType timerType, const QObject *r, const char *member) - : QObject(QAbstractEventDispatcher::instance()), hasValidReceiver(true), slotObj(0) + : QObject(QAbstractEventDispatcher::instance()), hasValidReceiver(true), slotObj(nullptr) { timerId = startTimer(msec, timerType); connect(this, SIGNAL(timeout()), r, member); @@ -290,7 +290,7 @@ QSingleShotTimer::QSingleShotTimer(int msec, Qt::TimerType timerType, const QObj if (r && thread() != r->thread()) { // Avoid leaking the QSingleShotTimer instance in case the application exits before the timer fires connect(QCoreApplication::instance(), &QCoreApplication::aboutToQuit, this, &QObject::deleteLater); - setParent(0); + setParent(nullptr); moveToThread(r->thread()); } } @@ -316,7 +316,7 @@ void QSingleShotTimer::timerEvent(QTimerEvent *) if (Q_LIKELY(!receiver.isNull() || !hasValidReceiver)) { // We allocate only the return type - we previously checked the function had // no arguments. - void *args[1] = { 0 }; + void *args[1] = { nullptr }; slotObj->call(const_cast<QObject*>(receiver.data()), args); } } else { diff --git a/src/corelib/kernel/qtimerinfo_unix.cpp b/src/corelib/kernel/qtimerinfo_unix.cpp index 39010c19cb..b425ca3dcb 100644 --- a/src/corelib/kernel/qtimerinfo_unix.cpp +++ b/src/corelib/kernel/qtimerinfo_unix.cpp @@ -83,7 +83,7 @@ QTimerInfoList::QTimerInfoList() } #endif - firstTimerInfo = 0; + firstTimerInfo = nullptr; } timespec QTimerInfoList::updateCurrentTime() @@ -389,7 +389,7 @@ bool QTimerInfoList::timerWait(timespec &tm) repairTimersIfNeeded(); // Find first waiting timer not already active - QTimerInfo *t = 0; + QTimerInfo *t = nullptr; for (QTimerInfoList::const_iterator it = constBegin(); it != constEnd(); ++it) { if (!(*it)->activateRef) { t = *it; @@ -450,7 +450,7 @@ void QTimerInfoList::registerTimer(int timerId, int interval, Qt::TimerType time t->interval = interval; t->timerType = timerType; t->obj = object; - t->activateRef = 0; + t->activateRef = nullptr; timespec expected = updateCurrentTime() + interval; @@ -514,9 +514,9 @@ bool QTimerInfoList::unregisterTimer(int timerId) // found it removeAt(i); if (t == firstTimerInfo) - firstTimerInfo = 0; + firstTimerInfo = nullptr; if (t->activateRef) - *(t->activateRef) = 0; + *(t->activateRef) = nullptr; delete t; return true; } @@ -535,9 +535,9 @@ bool QTimerInfoList::unregisterTimers(QObject *object) // object found removeAt(i); if (t == firstTimerInfo) - firstTimerInfo = 0; + firstTimerInfo = nullptr; if (t->activateRef) - *(t->activateRef) = 0; + *(t->activateRef) = nullptr; delete t; // move back one so that we don't skip the new current item --i; @@ -571,7 +571,7 @@ int QTimerInfoList::activateTimers() return 0; // nothing to do int n_act = 0, maxCount = 0; - firstTimerInfo = 0; + firstTimerInfo = nullptr; timespec currentTime = updateCurrentTime(); // qDebug() << "Thread" << QThread::currentThreadId() << "woken up at" << currentTime; @@ -643,11 +643,11 @@ int QTimerInfoList::activateTimers() QCoreApplication::sendEvent(currentTimerInfo->obj, &e); if (currentTimerInfo) - currentTimerInfo->activateRef = 0; + currentTimerInfo->activateRef = nullptr; } } - firstTimerInfo = 0; + firstTimerInfo = nullptr; // qDebug() << "Thread" << QThread::currentThreadId() << "activated" << n_act << "timers"; return n_act; } diff --git a/src/corelib/kernel/qtranslator.cpp b/src/corelib/kernel/qtranslator.cpp index 31c1277b03..4bd8874630 100644 --- a/src/corelib/kernel/qtranslator.cpp +++ b/src/corelib/kernel/qtranslator.cpp @@ -289,8 +289,8 @@ public: #if defined(QT_USE_MMAP) used_mmap(0), #endif - unmapPointer(0), unmapLength(0), resource(0), - messageArray(0), offsetArray(0), contextArray(0), numerusRulesArray(0), + unmapPointer(nullptr), unmapLength(0), resource(nullptr), + messageArray(nullptr), offsetArray(nullptr), contextArray(nullptr), numerusRulesArray(nullptr), messageLength(0), offsetLength(0), contextLength(0), numerusRulesLength(0) {} #if defined(QT_USE_MMAP) @@ -539,7 +539,7 @@ bool QTranslatorPrivate::do_load(const QString &realname, const QString &directo ok = true; } else { delete resource; - resource = 0; + resource = nullptr; } } @@ -610,8 +610,8 @@ bool QTranslatorPrivate::do_load(const QString &realname, const QString &directo delete [] unmapPointer; delete d->resource; - d->resource = 0; - d->unmapPointer = 0; + d->resource = nullptr; + d->unmapPointer = nullptr; d->unmapLength = 0; return false; @@ -874,10 +874,10 @@ bool QTranslatorPrivate::do_load(const uchar *data, qsizetype len, const QString } if (!ok) { - messageArray = 0; - contextArray = 0; - offsetArray = 0; - numerusRulesArray = 0; + messageArray = nullptr; + contextArray = nullptr; + offsetArray = nullptr; + numerusRulesArray = nullptr; messageLength = 0; contextLength = 0; offsetLength = 0; @@ -890,7 +890,7 @@ bool QTranslatorPrivate::do_load(const uchar *data, qsizetype len, const QString static QString getMessage(const uchar *m, const uchar *end, const char *context, const char *sourceText, const char *comment, uint numerus) { - const uchar *tn = 0; + const uchar *tn = nullptr; uint tn_length = 0; const uint sourceTextLen = uint(strlen(sourceText)); const uint contextLen = uint(strlen(context)); @@ -957,11 +957,11 @@ end: QString QTranslatorPrivate::do_translate(const char *context, const char *sourceText, const char *comment, int n) const { - if (context == 0) + if (context == nullptr) context = ""; - if (sourceText == 0) + if (sourceText == nullptr) sourceText = ""; - if (comment == 0) + if (comment == nullptr) comment = ""; uint numerus = 0; @@ -1076,13 +1076,13 @@ void QTranslatorPrivate::clear() } delete resource; - resource = 0; - unmapPointer = 0; + resource = nullptr; + unmapPointer = nullptr; unmapLength = 0; - messageArray = 0; - contextArray = 0; - offsetArray = 0; - numerusRulesArray = 0; + messageArray = nullptr; + contextArray = nullptr; + offsetArray = nullptr; + numerusRulesArray = nullptr; messageLength = 0; contextLength = 0; offsetLength = 0; diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp index 72f085d14b..fee1e3842d 100644 --- a/src/corelib/kernel/qvariant.cpp +++ b/src/corelib/kernel/qvariant.cpp @@ -2525,7 +2525,7 @@ void QVariant::load(QDataStream &s) return; } } - create(typeId, 0); + create(typeId, nullptr); d.is_null = is_null; if (!isValid()) { diff --git a/src/corelib/mimetypes/qmimedatabase.cpp b/src/corelib/mimetypes/qmimedatabase.cpp index ce84a15831..4d4f3eadeb 100644 --- a/src/corelib/mimetypes/qmimedatabase.cpp +++ b/src/corelib/mimetypes/qmimedatabase.cpp @@ -487,7 +487,7 @@ QMimeDatabase::QMimeDatabase() : */ QMimeDatabase::~QMimeDatabase() { - d = 0; + d = nullptr; } /*! diff --git a/src/corelib/mimetypes/qmimeprovider.cpp b/src/corelib/mimetypes/qmimeprovider.cpp index a3a6b9615c..c61759025c 100644 --- a/src/corelib/mimetypes/qmimeprovider.cpp +++ b/src/corelib/mimetypes/qmimeprovider.cpp @@ -130,7 +130,7 @@ bool QMimeBinaryProvider::CacheFile::reload() if (file.isOpen()) { file.close(); } - data = 0; + data = nullptr; return load(); } @@ -306,7 +306,7 @@ bool QMimeBinaryProvider::matchMagicRule(QMimeBinaryProvider::CacheFile *cacheFi const int valueLength = cacheFile->getUint32(off + 12); const int valueOffset = cacheFile->getUint32(off + 16); const int maskOffset = cacheFile->getUint32(off + 20); - const char *mask = maskOffset ? cacheFile->getCharStar(maskOffset) : NULL; + const char *mask = maskOffset ? cacheFile->getCharStar(maskOffset) : nullptr; if (!QMimeMagicRule::matchSubstring(dataPtr, dataSize, rangeStart, rangeLength, valueLength, cacheFile->getCharStar(valueOffset), mask)) continue; diff --git a/src/corelib/plugin/qfactoryloader.cpp b/src/corelib/plugin/qfactoryloader.cpp index 18f10c9b43..14de8db1c6 100644 --- a/src/corelib/plugin/qfactoryloader.cpp +++ b/src/corelib/plugin/qfactoryloader.cpp @@ -212,7 +212,7 @@ void QFactoryLoader::update() QStringList(QLatin1String("libplugins_%1_*.so").arg(d->suffix)), #endif QDir::Files); - QLibraryPrivate *library = 0; + QLibraryPrivate *library = nullptr; for (int j = 0; j < plugins.count(); ++j) { QString fileName = QDir::cleanPath(path + QLatin1Char('/') + plugins.at(j)); @@ -383,7 +383,7 @@ QObject *QFactoryLoader::instance(int index) const { Q_D(const QFactoryLoader); if (index < 0) - return 0; + return nullptr; #if QT_CONFIG(library) QMutexLocker lock(&d->mutex); @@ -399,7 +399,7 @@ QObject *QFactoryLoader::instance(int index) const return obj; } } - return 0; + return nullptr; } index -= d->libraryList.size(); lock.unlock(); @@ -416,7 +416,7 @@ QObject *QFactoryLoader::instance(int index) const --index; } - return 0; + return nullptr; } QMultiMap<int, QString> QFactoryLoader::keyMap() const diff --git a/src/corelib/plugin/qlibrary.cpp b/src/corelib/plugin/qlibrary.cpp index 39a170db3f..406a83c7dd 100644 --- a/src/corelib/plugin/qlibrary.cpp +++ b/src/corelib/plugin/qlibrary.cpp @@ -256,7 +256,7 @@ static bool findPatternUnloaded(const QString &library, QLibraryPrivate *lib) qsizetype fdlen = qMin(file.size(), MaxMemoryMapSize); const char *filedata = reinterpret_cast<char *>(file.map(0, fdlen)); - if (filedata == 0) { + if (filedata == nullptr) { // Try reading the data into memory instead (up to 64 MB). data = file.read(64 * 1024 * 1024); filedata = data.constData(); @@ -387,12 +387,12 @@ private: }; static QBasicMutex qt_library_mutex; -static QLibraryStore *qt_library_data = 0; +static QLibraryStore *qt_library_data = nullptr; static bool qt_library_data_once; QLibraryStore::~QLibraryStore() { - qt_library_data = 0; + qt_library_data = nullptr; } inline void QLibraryStore::cleanup() @@ -459,7 +459,7 @@ inline QLibraryPrivate *QLibraryStore::findOrCreate(const QString &fileName, con QLibraryStore *data = instance(); // check if this library is already loaded - QLibraryPrivate *lib = 0; + QLibraryPrivate *lib = nullptr; if (Q_LIKELY(data)) { lib = data->libraryMap.value(fileName); if (lib) @@ -498,7 +498,7 @@ inline void QLibraryStore::releaseLibrary(QLibraryPrivate *lib) } QLibraryPrivate::QLibraryPrivate(const QString &canonicalFileName, const QString &version, QLibrary::LoadHints loadHints) - : pHnd(0), fileName(canonicalFileName), fullVersion(version), instance(0), + : pHnd(nullptr), fileName(canonicalFileName), fullVersion(version), instance(nullptr), libraryRefCount(0), libraryUnloadCount(0), pluginState(MightBeAPlugin) { loadHintsInt.storeRelaxed(loadHints); @@ -528,7 +528,7 @@ void QLibraryPrivate::mergeLoadHints(QLibrary::LoadHints lh) QFunctionPointer QLibraryPrivate::resolve(const char *symbol) { if (!pHnd) - return 0; + return nullptr; return resolve_sys(symbol); } @@ -584,12 +584,12 @@ bool QLibraryPrivate::unload(UnloadFlag flag) //when the library is unloaded, we release the reference on it so that 'this' //can get deleted libraryRefCount.deref(); - pHnd = 0; - instance = 0; + pHnd = nullptr; + instance = nullptr; } } - return (pHnd == 0); + return (pHnd == nullptr); } void QLibraryPrivate::release() @@ -847,7 +847,7 @@ bool QLibrary::isLoaded() const Constructs a library with the given \a parent. */ QLibrary::QLibrary(QObject *parent) - :QObject(parent), d(0), did_load(false) + :QObject(parent), d(nullptr), did_load(false) { } @@ -862,7 +862,7 @@ QLibrary::QLibrary(QObject *parent) ".dylib" on \macos and iOS, and ".dll" on Windows. (See \l{fileName}.) */ QLibrary::QLibrary(const QString& fileName, QObject *parent) - :QObject(parent), d(0), did_load(false) + :QObject(parent), d(nullptr), did_load(false) { setFileName(fileName); } @@ -879,7 +879,7 @@ QLibrary::QLibrary(const QString& fileName, QObject *parent) ".dylib" on \macos and iOS, and ".dll" on Windows. (See \l{fileName}.) */ QLibrary::QLibrary(const QString& fileName, int verNum, QObject *parent) - :QObject(parent), d(0), did_load(false) + :QObject(parent), d(nullptr), did_load(false) { setFileNameAndVersion(fileName, verNum); } @@ -895,7 +895,7 @@ QLibrary::QLibrary(const QString& fileName, int verNum, QObject *parent) ".dylib" on \macos and iOS, and ".dll" on Windows. (See \l{fileName}.) */ QLibrary::QLibrary(const QString& fileName, const QString &version, QObject *parent) - :QObject(parent), d(0), did_load(false) + :QObject(parent), d(nullptr), did_load(false) { setFileNameAndVersion(fileName, version); } @@ -942,7 +942,7 @@ void QLibrary::setFileName(const QString &fileName) if (d) { lh = d->loadHints(); d->release(); - d = 0; + d = nullptr; did_load = false; } d = QLibraryPrivate::findOrCreate(fileName, QString(), lh); @@ -970,7 +970,7 @@ void QLibrary::setFileNameAndVersion(const QString &fileName, int verNum) if (d) { lh = d->loadHints(); d->release(); - d = 0; + d = nullptr; did_load = false; } d = QLibraryPrivate::findOrCreate(fileName, verNum >= 0 ? QString::number(verNum) : QString(), lh); @@ -991,7 +991,7 @@ void QLibrary::setFileNameAndVersion(const QString &fileName, const QString &ver if (d) { lh = d->loadHints(); d->release(); - d = 0; + d = nullptr; did_load = false; } d = QLibraryPrivate::findOrCreate(fileName, version, lh); @@ -1020,7 +1020,7 @@ void QLibrary::setFileNameAndVersion(const QString &fileName, const QString &ver QFunctionPointer QLibrary::resolve(const char *symbol) { if (!isLoaded() && !load()) - return 0; + return nullptr; return d->resolve(symbol); } diff --git a/src/corelib/plugin/qlibrary_unix.cpp b/src/corelib/plugin/qlibrary_unix.cpp index f0de1010d7..6eb84b327b 100644 --- a/src/corelib/plugin/qlibrary_unix.cpp +++ b/src/corelib/plugin/qlibrary_unix.cpp @@ -277,7 +277,7 @@ bool QLibraryPrivate::load_sys() qualifiedFileName = attempt; errorString.clear(); } - return (pHnd != 0); + return (pHnd != nullptr); } bool QLibraryPrivate::unload_sys() diff --git a/src/corelib/plugin/qpluginloader.cpp b/src/corelib/plugin/qpluginloader.cpp index c2443dbdda..aed1704d5f 100644 --- a/src/corelib/plugin/qpluginloader.cpp +++ b/src/corelib/plugin/qpluginloader.cpp @@ -136,7 +136,7 @@ QT_BEGIN_NAMESPACE Constructs a plugin loader with the given \a parent. */ QPluginLoader::QPluginLoader(QObject *parent) - : QObject(parent), d(0), did_load(false) + : QObject(parent), d(nullptr), did_load(false) { } @@ -152,7 +152,7 @@ QPluginLoader::QPluginLoader(QObject *parent) \sa setFileName() */ QPluginLoader::QPluginLoader(const QString &fileName, QObject *parent) - : QObject(parent), d(0), did_load(false) + : QObject(parent), d(nullptr), did_load(false) { setFileName(fileName); setLoadHints(QLibrary::PreventUnloadHint); @@ -195,7 +195,7 @@ QPluginLoader::~QPluginLoader() QObject *QPluginLoader::instance() { if (!isLoaded() && !load()) - return 0; + return nullptr; if (!d->inst && d->instance) d->inst = d->instance(); return d->inst.data(); @@ -363,7 +363,7 @@ void QPluginLoader::setFileName(const QString &fileName) if (d) { lh = d->loadHints(); d->release(); - d = 0; + d = nullptr; did_load = false; } diff --git a/src/corelib/serialization/qdatastream.h b/src/corelib/serialization/qdatastream.h index cc26f498dc..cd94f39b1f 100644 --- a/src/corelib/serialization/qdatastream.h +++ b/src/corelib/serialization/qdatastream.h @@ -316,7 +316,7 @@ template <typename Container> QDataStream &writeAssociativeContainer(QDataStream &s, const Container &c) { s << quint32(c.size()); -#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) && QT_DEPRECATED_SINCE(5, 15) // Deserialization should occur in the reverse order. // Otherwise, value() will return the least recently inserted // value instead of the most recently inserted one. diff --git a/src/corelib/statemachine/qabstractstate.cpp b/src/corelib/statemachine/qabstractstate.cpp index 0db44bc427..10f54c3e18 100644 --- a/src/corelib/statemachine/qabstractstate.cpp +++ b/src/corelib/statemachine/qabstractstate.cpp @@ -84,19 +84,19 @@ QT_BEGIN_NAMESPACE QAbstractStatePrivate::QAbstractStatePrivate(StateType type) - : stateType(type), isMachine(false), active(false), parentState(0) + : stateType(type), isMachine(false), active(false), parentState(nullptr) { } QStateMachine *QAbstractStatePrivate::machine() const { QObject *par = parent; - while (par != 0) { + while (par != nullptr) { if (QStateMachine *mach = qobject_cast<QStateMachine*>(par)) return mach; par = par->parent(); } - return 0; + return nullptr; } void QAbstractStatePrivate::callOnEntry(QEvent *e) diff --git a/src/corelib/statemachine/qabstracttransition.cpp b/src/corelib/statemachine/qabstracttransition.cpp index d841fd3c8b..df70b54721 100644 --- a/src/corelib/statemachine/qabstracttransition.cpp +++ b/src/corelib/statemachine/qabstracttransition.cpp @@ -144,7 +144,7 @@ QStateMachine *QAbstractTransitionPrivate::machine() const Q_Q(const QAbstractTransition); if (QHistoryState *parent = qobject_cast<QHistoryState *>(q->parent())) return parent->machine(); - return 0; + return nullptr; } bool QAbstractTransitionPrivate::callEventTest(QEvent *e) @@ -223,7 +223,7 @@ void QAbstractTransition::setTargetState(QAbstractState* target) { Q_D(QAbstractTransition); if ((d->targetStates.size() == 1 && target == d->targetStates.at(0).data()) || - (d->targetStates.isEmpty() && target == 0)) { + (d->targetStates.isEmpty() && target == nullptr)) { return; } if (!target) diff --git a/src/corelib/statemachine/qeventtransition.cpp b/src/corelib/statemachine/qeventtransition.cpp index a90f147773..5dcbcfff47 100644 --- a/src/corelib/statemachine/qeventtransition.cpp +++ b/src/corelib/statemachine/qeventtransition.cpp @@ -100,7 +100,7 @@ QT_BEGIN_NAMESPACE */ QEventTransitionPrivate::QEventTransitionPrivate() { - object = 0; + object = nullptr; eventType = QEvent::None; registered = false; } diff --git a/src/corelib/statemachine/qhistorystate.cpp b/src/corelib/statemachine/qhistorystate.cpp index ccf04d4799..e5b8075b96 100644 --- a/src/corelib/statemachine/qhistorystate.cpp +++ b/src/corelib/statemachine/qhistorystate.cpp @@ -147,7 +147,7 @@ protected: QHistoryStatePrivate::QHistoryStatePrivate() : QAbstractStatePrivate(HistoryState) - , defaultTransition(0) + , defaultTransition(nullptr) , historyType(QHistoryState::ShallowHistory) { } diff --git a/src/corelib/statemachine/qsignaltransition.cpp b/src/corelib/statemachine/qsignaltransition.cpp index 59e0c0d788..8e57695fd7 100644 --- a/src/corelib/statemachine/qsignaltransition.cpp +++ b/src/corelib/statemachine/qsignaltransition.cpp @@ -107,7 +107,7 @@ QT_BEGIN_NAMESPACE QSignalTransitionPrivate::QSignalTransitionPrivate() { - sender = 0; + sender = nullptr; signalIndex = -1; } diff --git a/src/corelib/statemachine/qstate.cpp b/src/corelib/statemachine/qstate.cpp index 62dd4f0284..f641d25a96 100644 --- a/src/corelib/statemachine/qstate.cpp +++ b/src/corelib/statemachine/qstate.cpp @@ -146,7 +146,7 @@ QT_BEGIN_NAMESPACE QStatePrivate::QStatePrivate() : QAbstractStatePrivate(StandardState), - errorState(0), initialState(0), childMode(QState::ExclusiveStates), + errorState(nullptr), initialState(nullptr), childMode(QState::ExclusiveStates), childStatesListNeedsRefresh(true), transitionsListNeedsRefresh(true) { } @@ -293,11 +293,11 @@ QAbstractState *QState::errorState() const void QState::setErrorState(QAbstractState *state) { Q_D(QState); - if (state != 0 && qobject_cast<QStateMachine*>(state)) { + if (state != nullptr && qobject_cast<QStateMachine*>(state)) { qWarning("QStateMachine::setErrorState: root state cannot be error state"); return; } - if (state != 0 && (!state->machine() || ((state->machine() != machine()) && !qobject_cast<QStateMachine*>(this)))) { + if (state != nullptr && (!state->machine() || ((state->machine() != machine()) && !qobject_cast<QStateMachine*>(this)))) { qWarning("QState::setErrorState: error state cannot belong " "to a different state machine"); return; @@ -360,15 +360,15 @@ QSignalTransition *QState::addTransition(const QObject *sender, const char *sign { if (!sender) { qWarning("QState::addTransition: sender cannot be null"); - return 0; + return nullptr; } if (!signal) { qWarning("QState::addTransition: signal cannot be null"); - return 0; + return nullptr; } if (!target) { qWarning("QState::addTransition: cannot add transition to null state"); - return 0; + return nullptr; } int offset = (*signal == '0'+QSIGNAL_CODE) ? 1 : 0; const QMetaObject *meta = sender->metaObject(); @@ -376,7 +376,7 @@ QSignalTransition *QState::addTransition(const QObject *sender, const char *sign if (meta->indexOfSignal(QMetaObject::normalizedSignature(signal+offset)) == -1) { qWarning("QState::addTransition: no such signal %s::%s", meta->className(), signal+offset); - return 0; + return nullptr; } } QSignalTransition *trans = new QSignalTransition(sender, signal); @@ -409,7 +409,7 @@ QAbstractTransition *QState::addTransition(QAbstractState *target) { if (!target) { qWarning("QState::addTransition: cannot add transition to null state"); - return 0; + return nullptr; } UnconditionalTransition *trans = new UnconditionalTransition(target); addTransition(trans); @@ -438,7 +438,7 @@ void QState::removeTransition(QAbstractTransition *transition) QStateMachinePrivate *mach = QStateMachinePrivate::get(d->machine()); if (mach) mach->unregisterTransition(transition); - transition->setParent(0); + transition->setParent(nullptr); } /*! @@ -544,7 +544,7 @@ bool QState::event(QEvent *e) d->childStatesListNeedsRefresh = true; d->transitionsListNeedsRefresh = true; if ((e->type() == QEvent::ChildRemoved) && (static_cast<QChildEvent *>(e)->child() == d->initialState)) - d->initialState = 0; + d->initialState = nullptr; } return QAbstractState::event(e); } diff --git a/src/corelib/statemachine/qstatemachine.cpp b/src/corelib/statemachine/qstatemachine.cpp index 009659d998..fb551d5197 100644 --- a/src/corelib/statemachine/qstatemachine.cpp +++ b/src/corelib/statemachine/qstatemachine.cpp @@ -197,7 +197,7 @@ struct CalculationCache { bool transitionDomainIsKnown : 1; TransitionInfo() - : transitionDomain(0) + : transitionDomain(nullptr) , effectiveTargetStatesIsKnown(false) , exitSetIsKnown(false) , transitionDomainIsKnown(false) @@ -289,9 +289,9 @@ child of a child, etc.) Otherwise returns 'false'. */ static inline bool isDescendant(const QAbstractState *state1, const QAbstractState *state2) { - Q_ASSERT(state1 != 0); + Q_ASSERT(state1 != nullptr); - for (QAbstractState *it = state1->parentState(); it != 0; it = it->parentState()) { + for (QAbstractState *it = state1->parentState(); it != nullptr; it = it->parentState()) { if (it == state2) return true; } @@ -311,7 +311,7 @@ static bool containsDecendantOf(const QSet<QAbstractState *> &states, const QAbs static int descendantDepth(const QAbstractState *state, const QAbstractState *ancestor) { int depth = 0; - for (const QAbstractState *it = state; it != 0; it = it->parentState()) { + for (const QAbstractState *it = state; it != nullptr; it = it->parentState()) { if (it == ancestor) break; ++depth; @@ -332,7 +332,7 @@ this returns the empty set. */ static QVector<QState*> getProperAncestors(const QAbstractState *state, const QAbstractState *upperBound) { - Q_ASSERT(state != 0); + Q_ASSERT(state != nullptr); QVector<QState*> result; result.reserve(16); for (QState *it = state->parentState(); it && it != upperBound; it = it->parentState()) { @@ -405,7 +405,7 @@ QStateMachinePrivate::QStateMachinePrivate() stopProcessingReason = EventQueueEmpty; error = QStateMachine::NoError; globalRestorePolicy = QState::DontRestoreProperties; - signalEventGenerator = 0; + signalEventGenerator = nullptr; #if QT_CONFIG(animation) animated = true; #endif @@ -437,7 +437,7 @@ static QEvent *cloneEvent(QEvent *e) Q_ASSERT_X(false, "cloneEvent()", "not implemented"); break; } - return 0; + return nullptr; } const QStateMachinePrivate::Handler qt_kernel_statemachine_handler = { @@ -474,10 +474,10 @@ bool QStateMachinePrivate::transitionStateEntryLessThan(QAbstractTransition *t1, } else if (isDescendant(s2, s1)) { return false; } else { - Q_ASSERT(s1->machine() != 0); + Q_ASSERT(s1->machine() != nullptr); QStateMachinePrivate *mach = QStateMachinePrivate::get(s1->machine()); QState *lca = mach->findLCA(QList<QAbstractState*>() << s1 << s2); - Q_ASSERT(lca != 0); + Q_ASSERT(lca != nullptr); int s1Depth = descendantDepth(s1, lca); int s2Depth = descendantDepth(s2, lca); if (s1Depth == s2Depth) @@ -497,10 +497,10 @@ bool QStateMachinePrivate::stateEntryLessThan(QAbstractState *s1, QAbstractState } else if (isDescendant(s2, s1)) { return true; } else { - Q_ASSERT(s1->machine() != 0); + Q_ASSERT(s1->machine() != nullptr); QStateMachinePrivate *mach = QStateMachinePrivate::get(s1->machine()); QState *lca = mach->findLCA(QList<QAbstractState*>() << s1 << s2); - Q_ASSERT(lca != 0); + Q_ASSERT(lca != nullptr); return (indexOfDescendant(lca, s1) < indexOfDescendant(lca, s2)); } } @@ -515,10 +515,10 @@ bool QStateMachinePrivate::stateExitLessThan(QAbstractState *s1, QAbstractState } else if (isDescendant(s2, s1)) { return false; } else { - Q_ASSERT(s1->machine() != 0); + Q_ASSERT(s1->machine() != nullptr); QStateMachinePrivate *mach = QStateMachinePrivate::get(s1->machine()); QState *lca = mach->findLCA(QList<QAbstractState*>() << s1 << s2); - Q_ASSERT(lca != 0); + Q_ASSERT(lca != nullptr); return (indexOfDescendant(lca, s2) < indexOfDescendant(lca, s1)); } } @@ -526,7 +526,7 @@ bool QStateMachinePrivate::stateExitLessThan(QAbstractState *s1, QAbstractState QState *QStateMachinePrivate::findLCA(const QList<QAbstractState*> &states, bool onlyCompound) { if (states.isEmpty()) - return 0; + return nullptr; QVector<QState*> ancestors = getProperAncestors(states.at(0), rootState()->parentState()); for (int i = 0; i < ancestors.size(); ++i) { QState *anc = ancestors.at(i); @@ -792,7 +792,7 @@ QSet<QAbstractState*> QStateMachinePrivate::computeExitSet_Unordered(QAbstractTr lst.prepend(t->sourceState()); domain = findLCCA(lst); - Q_ASSERT(domain != 0); + Q_ASSERT(domain != nullptr); } for (QAbstractState* s : qAsConst(configuration)) { @@ -918,7 +918,7 @@ QAbstractState *QStateMachinePrivate::getTransitionDomain(QAbstractTransition *t Q_ASSERT(cache); if (effectiveTargetStates.isEmpty()) - return 0; + return nullptr; QAbstractState *domain = nullptr; if (cache->transitionDomain(t, &domain)) @@ -1234,28 +1234,28 @@ QState *QStateMachinePrivate::toStandardState(QAbstractState *state) { if (state && (QAbstractStatePrivate::get(state)->stateType == QAbstractStatePrivate::StandardState)) return static_cast<QState*>(state); - return 0; + return nullptr; } const QState *QStateMachinePrivate::toStandardState(const QAbstractState *state) { if (state && (QAbstractStatePrivate::get(state)->stateType == QAbstractStatePrivate::StandardState)) return static_cast<const QState*>(state); - return 0; + return nullptr; } QFinalState *QStateMachinePrivate::toFinalState(QAbstractState *state) { if (state && (QAbstractStatePrivate::get(state)->stateType == QAbstractStatePrivate::FinalState)) return static_cast<QFinalState*>(state); - return 0; + return nullptr; } QHistoryState *QStateMachinePrivate::toHistoryState(QAbstractState *state) { if (state && (QAbstractStatePrivate::get(state)->stateType == QAbstractStatePrivate::HistoryState)) return static_cast<QHistoryState*>(state); - return 0; + return nullptr; } bool QStateMachinePrivate::isInFinalState(QAbstractState* s) const @@ -1455,13 +1455,13 @@ QHash<QAbstractState*, QVector<QPropertyAssignment> > QStateMachinePrivate::comp QAbstractState *QStateMachinePrivate::findErrorState(QAbstractState *context) { // Find error state recursively in parent hierarchy if not set explicitly for context state - QAbstractState *errorState = 0; - if (context != 0) { + QAbstractState *errorState = nullptr; + if (context != nullptr) { QState *s = toStandardState(context); - if (s != 0) + if (s != nullptr) errorState = s->errorState(); - if (errorState == 0) + if (errorState == nullptr) errorState = findErrorState(context->parentState()); } @@ -1475,21 +1475,21 @@ void QStateMachinePrivate::setError(QStateMachine::Error errorCode, QAbstractSta error = errorCode; switch (errorCode) { case QStateMachine::NoInitialStateError: - Q_ASSERT(currentContext != 0); + Q_ASSERT(currentContext != nullptr); errorString = QStateMachine::tr("Missing initial state in compound state '%1'") .arg(currentContext->objectName()); break; case QStateMachine::NoDefaultStateInHistoryStateError: - Q_ASSERT(currentContext != 0); + Q_ASSERT(currentContext != nullptr); errorString = QStateMachine::tr("Missing default state in history state '%1'") .arg(currentContext->objectName()); break; case QStateMachine::NoCommonAncestorForTransitionError: - Q_ASSERT(currentContext != 0); + Q_ASSERT(currentContext != nullptr); errorString = QStateMachine::tr("No common ancestor for targets and source of transition from state '%1'") .arg(currentContext->objectName()); @@ -1513,11 +1513,11 @@ void QStateMachinePrivate::setError(QStateMachine::Error errorCode, QAbstractSta // Avoid infinite loop if the error state itself has an error if (currentContext == currentErrorState) - currentErrorState = 0; + currentErrorState = nullptr; Q_ASSERT(currentErrorState != rootState()); - if (currentErrorState != 0) { + if (currentErrorState != nullptr) { #ifdef QSTATEMACHINE_DEBUG qDebug() << q << ": entering error state" << currentErrorState << "from" << currentContext; #endif @@ -1549,7 +1549,7 @@ QStateMachinePrivate::initializeAnimation(QAbstractAnimation *abstractAnimation, } } else { QPropertyAnimation *animation = qobject_cast<QPropertyAnimation *>(abstractAnimation); - if (animation != 0 + if (animation != nullptr && prop.object == animation->targetObject() && prop.propertyName == animation->propertyName()) { @@ -1568,7 +1568,7 @@ void QStateMachinePrivate::_q_animationFinished() { Q_Q(QStateMachine); QAbstractAnimation *anim = qobject_cast<QAbstractAnimation*>(q->sender()); - Q_ASSERT(anim != 0); + Q_ASSERT(anim != nullptr); QObject::disconnect(anim, SIGNAL(finished()), q, SLOT(_q_animationFinished())); if (resetAnimationEndValues.contains(anim)) { qobject_cast<QVariantAnimation*>(anim)->setEndValue(QVariant()); // ### generalize @@ -1576,7 +1576,7 @@ void QStateMachinePrivate::_q_animationFinished() } QAbstractState *state = stateForAnimation.take(anim); - Q_ASSERT(state != 0); + Q_ASSERT(state != nullptr); #ifndef QT_NO_PROPERTIES // Set the final property value. @@ -1638,7 +1638,7 @@ void QStateMachinePrivate::terminateActiveAnimations(QAbstractState *state, resetAnimationEndValues.remove(anim); } QPropertyAssignment assn = propertyForAnimation.take(anim); - Q_ASSERT(assn.object != 0); + Q_ASSERT(assn.object != nullptr); // If there is no property assignment that sets this property, // set the property to its target value. bool found = false; @@ -1745,7 +1745,7 @@ QAbstractTransition *QStateMachinePrivate::createInitialTransition() const }; QState *root = rootState(); - Q_ASSERT(root != 0); + Q_ASSERT(root != nullptr); QList<QAbstractState *> targets; switch (root->childMode()) { case QState::ExclusiveStates: @@ -1891,26 +1891,26 @@ void QStateMachinePrivate::_q_process() enabledTransitions = selectTransitions(e, &calculationCache); if (enabledTransitions.isEmpty()) { delete e; - e = 0; + e = nullptr; } - while (enabledTransitions.isEmpty() && ((e = dequeueInternalEvent()) != 0)) { + while (enabledTransitions.isEmpty() && ((e = dequeueInternalEvent()) != nullptr)) { #ifdef QSTATEMACHINE_DEBUG qDebug() << q << ": dequeued internal event" << e << "of type" << e->type(); #endif enabledTransitions = selectTransitions(e, &calculationCache); if (enabledTransitions.isEmpty()) { delete e; - e = 0; + e = nullptr; } } - while (enabledTransitions.isEmpty() && ((e = dequeueExternalEvent()) != 0)) { + while (enabledTransitions.isEmpty() && ((e = dequeueExternalEvent()) != nullptr)) { #ifdef QSTATEMACHINE_DEBUG qDebug() << q << ": dequeued external event" << e << "of type" << e->type(); #endif enabledTransitions = selectTransitions(e, &calculationCache); if (enabledTransitions.isEmpty()) { delete e; - e = 0; + e = nullptr; } } if (enabledTransitions.isEmpty()) { @@ -2009,7 +2009,7 @@ QEvent *QStateMachinePrivate::dequeueInternalEvent() { QMutexLocker locker(&internalEventMutex); if (internalEventQueue.isEmpty()) - return 0; + return nullptr; return internalEventQueue.takeFirst(); } @@ -2017,7 +2017,7 @@ QEvent *QStateMachinePrivate::dequeueExternalEvent() { QMutexLocker locker(&externalEventMutex); if (externalEventQueue.isEmpty()) - return 0; + return nullptr; return externalEventQueue.takeFirst(); } @@ -2175,15 +2175,15 @@ void QStateMachinePrivate::goToState(QAbstractState *targetState) return; Q_ASSERT(state == Running); - QState *sourceState = 0; + QState *sourceState = nullptr; QSet<QAbstractState*>::const_iterator it; for (it = configuration.constBegin(); it != configuration.constEnd(); ++it) { sourceState = toStandardState(*it); - if (sourceState != 0) + if (sourceState != nullptr) break; } - Q_ASSERT(sourceState != 0); + Q_ASSERT(sourceState != nullptr); // Reuse previous GoToStateTransition in case of several calls to // goToState() in a row. GoToStateTransition *trans = sourceState->findChild<GoToStateTransition*>(); @@ -2327,7 +2327,7 @@ void QStateMachinePrivate::unregisterSignalTransition(QSignalTransition *transit Q_ASSERT(connectedSignalIndexes.size() > signalIndex); Q_ASSERT(connectedSignalIndexes.at(signalIndex) != 0); if (--connectedSignalIndexes[signalIndex] == 0) { - Q_ASSERT(signalEventGenerator != 0); + Q_ASSERT(signalEventGenerator != nullptr); static const int generatorMethodOffset = QSignalEventGenerator::staticMetaObject.methodOffset(); QMetaObject::disconnect(sender, signalIndex, signalEventGenerator, generatorMethodOffset); int sum = 0; @@ -2454,7 +2454,7 @@ void QStateMachinePrivate::handleTransitionSignal(QObject *sender, int signalInd Constructs a new state machine with the given \a parent. */ QStateMachine::QStateMachine(QObject *parent) - : QState(*new QStateMachinePrivate, /*parentState=*/0) + : QState(*new QStateMachinePrivate, /*parentState=*/nullptr) { // Can't pass the parent to the QState constructor, as it expects a QState // But this works as expected regardless of whether parent is a QState or not @@ -2472,7 +2472,7 @@ QStateMachine::QStateMachine(QObject *parent) state machine is invalid, and might work incorrectly. */ QStateMachine::QStateMachine(QState::ChildMode childMode, QObject *parent) - : QState(*new QStateMachinePrivate, /*parentState=*/0) + : QState(*new QStateMachinePrivate, /*parentState=*/nullptr) { Q_D(QStateMachine); d->childMode = childMode; @@ -2495,7 +2495,7 @@ QStateMachine::QStateMachine(QState::ChildMode childMode, QObject *parent) \internal */ QStateMachine::QStateMachine(QStateMachinePrivate &dd, QObject *parent) - : QState(dd, /*parentState=*/0) + : QState(dd, /*parentState=*/nullptr) { setParent(parent); } @@ -2637,7 +2637,7 @@ void QStateMachine::removeState(QAbstractState *state) state, QAbstractStatePrivate::get(state)->machine(), this); return; } - state->setParent(0); + state->setParent(nullptr); } bool QStateMachine::isRunning() const @@ -2661,7 +2661,7 @@ void QStateMachine::start() { Q_D(QStateMachine); - if ((childMode() == QState::ExclusiveStates) && (initialState() == 0)) { + if ((childMode() == QState::ExclusiveStates) && (initialState() == nullptr)) { qWarning("QStateMachine::start: No initial state set for machine. Refusing to start."); return; } @@ -2897,7 +2897,7 @@ bool QStateMachine::event(QEvent *e) d->delayedEventsMutex.lock(); int id = d->timerIdToDelayedEventId.take(tid); QStateMachinePrivate::DelayedEvent ee = d->delayedEvents.take(id); - if (ee.event != 0) { + if (ee.event != nullptr) { Q_ASSERT(ee.timerId == tid); killTimer(tid); d->delayedEventIdFreeList.release(id); diff --git a/src/corelib/text/qbytearray.cpp b/src/corelib/text/qbytearray.cpp index 3f5fef80e2..83182dbd93 100644 --- a/src/corelib/text/qbytearray.cpp +++ b/src/corelib/text/qbytearray.cpp @@ -2,6 +2,7 @@ ** ** Copyright (C) 2019 The Qt Company Ltd. ** Copyright (C) 2016 Intel Corporation. +** Copyright (C) 2019 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtCore module of the Qt Toolkit. @@ -41,6 +42,7 @@ #include "qbytearray.h" #include "qbytearraymatcher.h" #include "private/qtools_p.h" +#include "qhashfunctions.h" #include "qstring.h" #include "qlist.h" #include "qlocale.h" @@ -986,10 +988,20 @@ QByteArray qUncompress(const uchar* data, int nbytes) four. \value OmitTrailingEquals Omits adding the padding equal signs at the end of the encoded data. - - QByteArray::fromBase64() ignores the KeepTrailingEquals and - OmitTrailingEquals options and will not flag errors in case they are - missing or if there are too many of them. + \value IgnoreBase64DecodingErrors When decoding Base64-encoded data, ignores errors + in the input; invalid characters are simply skipped. + This enum value has been added in Qt 5.15. + \value AbortOnBase64DecodingErrors When decoding Base64-encoded data, stops at the first + decoding error. + This enum value has been added in Qt 5.15. + + QByteArray::fromBase64Encoding() and QByteArray::fromBase64() + ignore the KeepTrailingEquals and OmitTrailingEquals options. If + the IgnoreBase64DecodingErrors option is specified, they will not + flag errors in case trailing equal signs are missing or if there + are too many of them. If instead the AbortOnBase64DecodingErrors is + specified, then the input must either have no padding or have the + correct amount of equal signs. */ /*! \fn QByteArray::iterator QByteArray::begin() @@ -4411,63 +4423,166 @@ QByteArray &QByteArray::setRawData(const char *data, uint size) return *this; } -/*! - \since 5.2 - - Returns a decoded copy of the Base64 array \a base64, using the alphabet - defined by \a options. Input is not checked for validity; invalid - characters in the input are skipped, enabling the decoding process to - continue with subsequent characters. - - For example: - - \snippet code/src_corelib_tools_qbytearray.cpp 44 - - The algorithm used to decode Base64-encoded data is defined in \l{RFC 4648}. +namespace { +struct fromBase64_helper_result { + qsizetype decodedLength; + QByteArray::Base64DecodingStatus status; +}; - \sa toBase64() -*/ -QByteArray QByteArray::fromBase64(const QByteArray &base64, Base64Options options) +fromBase64_helper_result fromBase64_helper(const char *input, qsizetype inputSize, + char *output /* may alias input */, + QByteArray::Base64Options options) { + fromBase64_helper_result result{ 0, QByteArray::Base64DecodingStatus::Ok }; + unsigned int buf = 0; int nbits = 0; - QByteArray tmp((base64.size() * 3) / 4, Qt::Uninitialized); - int offset = 0; - for (int i = 0; i < base64.size(); ++i) { - int ch = base64.at(i); + qsizetype offset = 0; + for (qsizetype i = 0; i < inputSize; ++i) { + int ch = input[i]; int d; - if (ch >= 'A' && ch <= 'Z') + if (ch >= 'A' && ch <= 'Z') { d = ch - 'A'; - else if (ch >= 'a' && ch <= 'z') + } else if (ch >= 'a' && ch <= 'z') { d = ch - 'a' + 26; - else if (ch >= '0' && ch <= '9') + } else if (ch >= '0' && ch <= '9') { d = ch - '0' + 52; - else if (ch == '+' && (options & Base64UrlEncoding) == 0) + } else if (ch == '+' && (options & QByteArray::Base64UrlEncoding) == 0) { d = 62; - else if (ch == '-' && (options & Base64UrlEncoding) != 0) + } else if (ch == '-' && (options & QByteArray::Base64UrlEncoding) != 0) { d = 62; - else if (ch == '/' && (options & Base64UrlEncoding) == 0) + } else if (ch == '/' && (options & QByteArray::Base64UrlEncoding) == 0) { d = 63; - else if (ch == '_' && (options & Base64UrlEncoding) != 0) + } else if (ch == '_' && (options & QByteArray::Base64UrlEncoding) != 0) { d = 63; - else - d = -1; + } else { + if (options & QByteArray::AbortOnBase64DecodingErrors) { + if (ch == '=') { + // can have 1 or 2 '=' signs, in both cases padding base64Size to + // a multiple of 4. Any other case is illegal. + if ((inputSize % 4) != 0) { + result.status = QByteArray::Base64DecodingStatus::IllegalInputLength; + return result; + } else if ((i == inputSize - 1) || + (i == inputSize - 2 && input[++i] == '=')) { + d = -1; // ... and exit the loop, normally + } else { + result.status = QByteArray::Base64DecodingStatus::IllegalPadding; + return result; + } + } else { + result.status = QByteArray::Base64DecodingStatus::IllegalCharacter; + return result; + } + } else { + d = -1; + } + } if (d != -1) { buf = (buf << 6) | d; nbits += 6; if (nbits >= 8) { nbits -= 8; - tmp[offset++] = buf >> nbits; + Q_ASSERT(offset < i); + output[offset++] = buf >> nbits; buf &= (1 << nbits) - 1; } } } - tmp.truncate(offset); - return tmp; + result.decodedLength = offset; + return result; +} +} // anonymous namespace + +/*! + \fn QByteArray::FromBase64Result QByteArray::fromBase64Encoding(QByteArray &&base64, Base64Options options) + \fn QByteArray::FromBase64Result QByteArray::fromBase64Encoding(const QByteArray &base64, Base64Options options) + \since 5.15 + \overload + + Decodes the Base64 array \a base64, using the options + defined by \a options. If \a options contains \c{IgnoreBase64DecodingErrors} + (the default), the input is not checked for validity; invalid + characters in the input are skipped, enabling the decoding process to + continue with subsequent characters. If \a options contains + \c{AbortOnBase64DecodingErrors}, then decoding will stop at the first + invalid character. + + For example: + + \snippet code/src_corelib_tools_qbytearray.cpp 44ter + + The algorithm used to decode Base64-encoded data is defined in \l{RFC 4648}. + + Returns a QByteArrayFromBase64Result object, containing the decoded + data and a flag telling whether decoding was successful. If the + \c{AbortOnBase64DecodingErrors} option was passed and the input + data was invalid, it is unspecified what the decoded data contains. + + \sa toBase64() +*/ +QByteArray::FromBase64Result QByteArray::fromBase64Encoding(QByteArray &&base64, Base64Options options) +{ + // try to avoid a detach when calling data(), as it would over-allocate + // (we need less space when decoding than the one required by the full copy) + if (base64.isDetached()) { + const auto base64result = fromBase64_helper(base64.data(), + base64.size(), + base64.data(), // in-place + options); + base64.truncate(int(base64result.decodedLength)); + return { std::move(base64), base64result.status }; + } + + return fromBase64Encoding(base64, options); +} + + +QByteArray::FromBase64Result QByteArray::fromBase64Encoding(const QByteArray &base64, Base64Options options) +{ + const auto base64Size = base64.size(); + QByteArray result((base64Size * 3) / 4, Qt::Uninitialized); + const auto base64result = fromBase64_helper(base64.data(), + base64Size, + const_cast<char *>(result.constData()), + options); + result.truncate(int(base64result.decodedLength)); + return { std::move(result), base64result.status }; +} + +/*! + \since 5.2 + + Returns a decoded copy of the Base64 array \a base64, using the options + defined by \a options. If \a options contains \c{IgnoreBase64DecodingErrors} + (the default), the input is not checked for validity; invalid + characters in the input are skipped, enabling the decoding process to + continue with subsequent characters. If \a options contains + \c{AbortOnBase64DecodingErrors}, then decoding will stop at the first + invalid character. + + For example: + + \snippet code/src_corelib_tools_qbytearray.cpp 44 + + The algorithm used to decode Base64-encoded data is defined in \l{RFC 4648}. + + Returns the decoded data, or, if the \c{AbortOnBase64DecodingErrors} + option was passed and the input data was invalid, an empty byte array. + + \note The fromBase64Encoding() function is recommended in new code. + + \sa toBase64(), fromBase64Encoding() +*/ +QByteArray QByteArray::fromBase64(const QByteArray &base64, Base64Options options) +{ + if (auto result = fromBase64Encoding(base64, options)) + return std::move(result.decoded); + return QByteArray(); } /*! @@ -4838,4 +4953,86 @@ QByteArray QByteArray::toPercentEncoding(const QByteArray &exclude, const QByteA \sa QStringLiteral */ +/*! + \class QByteArray::FromBase64Result + \inmodule QtCore + \ingroup tools + \since 5.15 + + \brief The QByteArray::FromBase64Result class holds the result of + a call to QByteArray::fromBase64Encoding. + + Objects of this class can be used to check whether the conversion + was successful, and if so, retrieve the decoded QByteArray. The + conversion operators defined for QByteArray::FromBase64Result make + its usage straightforward: + + \snippet code/src_corelib_tools_qbytearray.cpp 44ter + + In alternative, it is possible to access the conversion status + and the decoded data directly: + + \snippet code/src_corelib_tools_qbytearray.cpp 44quater + + \sa QByteArray::fromBase64 +*/ + +/*! + \variable QByteArray::FromBase64Result::decoded + + Contains the decoded byte array. +*/ + +/*! + \variable QByteArray::FromBase64Result::decodingStatus + + Contains whether the decoding was successful, expressed as a value + of type QByteArray::Base64DecodingStatus. +*/ + +/*! + \fn QByteArray::FromBase64Result::operator bool() const + + Returns whether the decoding was successful. This is equivalent + to checking whether the \c{decodingStatus} member is equal to + QByteArray::Base64DecodingStatus::Ok. +*/ + +/*! + \fn QByteArray::FromBase64Result::operator QByteArray() const + + Returns the decoded byte array. +*/ + +/*! + \fn bool operator==(const QByteArray::FromBase64Result &lhs, const QByteArray::FromBase64Result &rhs) noexcept + \relates QByteArray::FromBase64Result + + Compares \a lhs and \a rhs for equality. \a lhs and \a rhs are equal + if and only if they contain the same decoding status and, if the + status is QByteArray::Base64DecodingStatus::Ok, if and only if + they contain the same decoded data. +*/ + +/*! + \fn bool operator!=(const QByteArray::FromBase64Result &lhs, const QByteArray::FromBase64Result &rhs) noexcept + \relates QByteArray::FromBase64Result + + Compares \a lhs and \a rhs for inequality. +*/ + +/*! + \relates QByteArray::FromBase64Result + + Returns the hash value for \a key, using + \a seed to seed the calculation. +*/ +uint qHash(const QByteArray::FromBase64Result &key, uint seed) noexcept +{ + QtPrivate::QHashCombine hash; + seed = hash(seed, key.decoded); + seed = hash(seed, static_cast<int>(key.decodingStatus)); + return seed; +} + QT_END_NAMESPACE diff --git a/src/corelib/text/qbytearray.h b/src/corelib/text/qbytearray.h index af8e4da36d..fa87ebf058 100644 --- a/src/corelib/text/qbytearray.h +++ b/src/corelib/text/qbytearray.h @@ -145,10 +145,20 @@ public: Base64UrlEncoding = 1, KeepTrailingEquals = 0, - OmitTrailingEquals = 2 + OmitTrailingEquals = 2, + + IgnoreBase64DecodingErrors = 0, + AbortOnBase64DecodingErrors = 4, }; Q_DECLARE_FLAGS(Base64Options, Base64Option) + enum class Base64DecodingStatus { + Ok, + IllegalInputLength, + IllegalCharacter, + IllegalPadding, + }; + inline QByteArray() noexcept; QByteArray(const char *, int size = -1); QByteArray(int size, char c); @@ -356,8 +366,11 @@ public: Q_REQUIRED_RESULT static QByteArray number(qulonglong, int base = 10); Q_REQUIRED_RESULT static QByteArray number(double, char f = 'g', int prec = 6); Q_REQUIRED_RESULT static QByteArray fromRawData(const char *, int size); - Q_REQUIRED_RESULT static QByteArray fromBase64(const QByteArray &base64, - Base64Options options = Base64Encoding); + + class FromBase64Result; + Q_REQUIRED_RESULT static FromBase64Result fromBase64Encoding(QByteArray &&base64, Base64Options options = Base64Encoding); + Q_REQUIRED_RESULT static FromBase64Result fromBase64Encoding(const QByteArray &base64, Base64Options options = Base64Encoding); + Q_REQUIRED_RESULT static QByteArray fromBase64(const QByteArray &base64, Base64Options options = Base64Encoding); Q_REQUIRED_RESULT static QByteArray fromHex(const QByteArray &hexEncoded); Q_REQUIRED_RESULT static QByteArray fromPercentEncoding(const QByteArray &pctEncoded, char percent = '%'); @@ -642,6 +655,50 @@ inline QByteArray qUncompress(const QByteArray& data) Q_DECLARE_SHARED(QByteArray) +class QByteArray::FromBase64Result +{ +public: + QByteArray decoded; + QByteArray::Base64DecodingStatus decodingStatus; + + void swap(QByteArray::FromBase64Result &other) noexcept + { + qSwap(decoded, other.decoded); + qSwap(decodingStatus, other.decodingStatus); + } + + explicit operator bool() const noexcept { return decodingStatus == QByteArray::Base64DecodingStatus::Ok; } + +#if defined(Q_COMPILER_REF_QUALIFIERS) && !defined(Q_QDOC) + QByteArray &operator*() & noexcept { return decoded; } + const QByteArray &operator*() const & noexcept { return decoded; } + QByteArray &&operator*() && noexcept { return std::move(decoded); } +#else + QByteArray &operator*() noexcept { return decoded; } + const QByteArray &operator*() const noexcept { return decoded; } +#endif +}; + +Q_DECLARE_SHARED(QByteArray::FromBase64Result) + +inline bool operator==(const QByteArray::FromBase64Result &lhs, const QByteArray::FromBase64Result &rhs) noexcept +{ + if (lhs.decodingStatus != rhs.decodingStatus) + return false; + + if (lhs.decodingStatus == QByteArray::Base64DecodingStatus::Ok && lhs.decoded != rhs.decoded) + return false; + + return true; +} + +inline bool operator!=(const QByteArray::FromBase64Result &lhs, const QByteArray::FromBase64Result &rhs) noexcept +{ + return !operator==(lhs, rhs); +} + +Q_CORE_EXPORT Q_DECL_PURE_FUNCTION uint qHash(const QByteArray::FromBase64Result &key, uint seed = 0) noexcept; + QT_END_NAMESPACE #endif // QBYTEARRAY_H diff --git a/src/corelib/text/qlocale.cpp b/src/corelib/text/qlocale.cpp index 75a5bc802e..694d491273 100644 --- a/src/corelib/text/qlocale.cpp +++ b/src/corelib/text/qlocale.cpp @@ -79,7 +79,7 @@ QT_BEGIN_NAMESPACE #ifndef QT_NO_SYSTEMLOCALE -static QSystemLocale *_systemLocale = 0; +static QSystemLocale *_systemLocale = nullptr; class QSystemLocaleSingleton: public QSystemLocale { public: @@ -695,7 +695,7 @@ QSystemLocale::QSystemLocale(bool) QSystemLocale::~QSystemLocale() { if (_systemLocale == this) { - _systemLocale = 0; + _systemLocale = nullptr; globalLocaleData.m_language_id = 0; } @@ -2429,7 +2429,7 @@ QTime QLocale::toTime(const QString &string, const QString &format, QCalendar ca QDateTimeParser dt(QVariant::Time, QDateTimeParser::FromString, cal); dt.setDefaultLocale(*this); if (dt.parseFormat(format)) - dt.fromString(string, 0, &time); + dt.fromString(string, nullptr, &time); #else Q_UNUSED(cal); Q_UNUSED(string); @@ -2468,7 +2468,7 @@ QDate QLocale::toDate(const QString &string, const QString &format, QCalendar ca QDateTimeParser dt(QVariant::Date, QDateTimeParser::FromString, cal); dt.setDefaultLocale(*this); if (dt.parseFormat(format)) - dt.fromString(string, &date, 0); + dt.fromString(string, &date, nullptr); #else Q_UNUSED(string); Q_UNUSED(format); diff --git a/src/corelib/text/qlocale_tools.cpp b/src/corelib/text/qlocale_tools.cpp index c246028b4d..0da769d694 100644 --- a/src/corelib/text/qlocale_tools.cpp +++ b/src/corelib/text/qlocale_tools.cpp @@ -322,7 +322,7 @@ double qt_asciiToDouble(const char *num, int numLen, bool &ok, int &processed, conv_flags = double_conversion::StringToDoubleConverter::ALLOW_LEADING_SPACES | double_conversion::StringToDoubleConverter::ALLOW_TRAILING_SPACES; } - double_conversion::StringToDoubleConverter conv(conv_flags, 0.0, qt_qnan(), 0, 0); + double_conversion::StringToDoubleConverter conv(conv_flags, 0.0, qt_qnan(), nullptr, nullptr); d = conv.StringToDouble(num, numLen, &processed); if (!qIsFinite(d)) { diff --git a/src/corelib/text/qregularexpression.cpp b/src/corelib/text/qregularexpression.cpp index d0bdc0d45c..e05bef450b 100644 --- a/src/corelib/text/qregularexpression.cpp +++ b/src/corelib/text/qregularexpression.cpp @@ -831,7 +831,7 @@ struct QRegularExpressionPrivate : QSharedData QRegularExpression::MatchType matchType, QRegularExpression::MatchOptions matchOptions, CheckSubjectStringOption checkSubjectStringOption = CheckSubjectString, - const QRegularExpressionMatchPrivate *previous = 0) const; + const QRegularExpressionMatchPrivate *previous = nullptr) const; int captureIndexForName(QStringView name) const; @@ -990,7 +990,7 @@ void QRegularExpressionPrivate::compilePattern() options, &errorCode, &patternErrorOffset, - NULL); + nullptr); if (!compiledPattern) { errorOffset = static_cast<int>(patternErrorOffset); @@ -1049,7 +1049,7 @@ public: { // The default JIT stack size in PCRE is 32K, // we allocate from 32K up to 512K. - stack = pcre2_jit_stack_create_16(32 * 1024, 512 * 1024, NULL); + stack = pcre2_jit_stack_create_16(32 * 1024, 512 * 1024, nullptr); } /*! \internal @@ -1073,7 +1073,7 @@ static pcre2_jit_stack_16 *qtPcreCallback(void *) if (jitStacks()->hasLocalData()) return jitStacks()->localData()->stack; - return 0; + return nullptr; } /*! @@ -1240,9 +1240,9 @@ QRegularExpressionMatchPrivate *QRegularExpressionPrivate::doMatch(const QString previousMatchWasEmpty = true; } - pcre2_match_context_16 *matchContext = pcre2_match_context_create_16(NULL); - pcre2_jit_stack_assign_16(matchContext, &qtPcreCallback, NULL); - pcre2_match_data_16 *matchData = pcre2_match_data_create_from_pattern_16(compiledPattern, NULL); + pcre2_match_context_16 *matchContext = pcre2_match_context_create_16(nullptr); + pcre2_jit_stack_assign_16(matchContext, &qtPcreCallback, nullptr); + pcre2_match_data_16 *matchData = pcre2_match_data_create_from_pattern_16(compiledPattern, nullptr); const unsigned short * const subjectUtf16 = subject.utf16() + subjectStart; diff --git a/src/corelib/text/qtextboundaryfinder.cpp b/src/corelib/text/qtextboundaryfinder.cpp index 070b041220..ebdba6b2c5 100644 --- a/src/corelib/text/qtextboundaryfinder.cpp +++ b/src/corelib/text/qtextboundaryfinder.cpp @@ -161,10 +161,10 @@ static void init(QTextBoundaryFinder::BoundaryType type, const QChar *chars, int */ QTextBoundaryFinder::QTextBoundaryFinder() : t(Grapheme) - , chars(0) + , chars(nullptr) , length(0) , freePrivate(true) - , d(0) + , d(nullptr) { } @@ -178,7 +178,7 @@ QTextBoundaryFinder::QTextBoundaryFinder(const QTextBoundaryFinder &other) , length(other.length) , pos(other.pos) , freePrivate(true) - , d(0) + , d(nullptr) { if (other.d) { Q_ASSERT(length > 0); @@ -199,7 +199,7 @@ QTextBoundaryFinder &QTextBoundaryFinder::operator=(const QTextBoundaryFinder &o if (other.d) { Q_ASSERT(other.length > 0); uint newCapacity = (other.length + 1) * sizeof(QCharAttributes); - QTextBoundaryFinderPrivate *newD = (QTextBoundaryFinderPrivate *) realloc(freePrivate ? d : 0, newCapacity); + QTextBoundaryFinderPrivate *newD = (QTextBoundaryFinderPrivate *) realloc(freePrivate ? d : nullptr, newCapacity); Q_CHECK_PTR(newD); freePrivate = true; d = newD; @@ -216,7 +216,7 @@ QTextBoundaryFinder &QTextBoundaryFinder::operator=(const QTextBoundaryFinder &o } else { if (freePrivate) free(d); - d = 0; + d = nullptr; } return *this; @@ -242,7 +242,7 @@ QTextBoundaryFinder::QTextBoundaryFinder(BoundaryType type, const QString &strin , length(string.length()) , pos(0) , freePrivate(true) - , d(0) + , d(nullptr) { if (length > 0) { d = (QTextBoundaryFinderPrivate *) malloc((length + 1) * sizeof(QCharAttributes)); @@ -271,7 +271,7 @@ QTextBoundaryFinder::QTextBoundaryFinder(BoundaryType type, const QChar *chars, , length(length) , pos(0) , freePrivate(true) - , d(0) + , d(nullptr) { if (!chars) { length = 0; diff --git a/src/corelib/thread/qexception.cpp b/src/corelib/thread/qexception.cpp index a3e30d5a7a..f9c63085b7 100644 --- a/src/corelib/thread/qexception.cpp +++ b/src/corelib/thread/qexception.cpp @@ -199,7 +199,7 @@ void ExceptionStore::setException(const QException &e) bool ExceptionStore::hasException() const { - return (exceptionHolder.exception() != 0); + return (exceptionHolder.exception() != nullptr); } ExceptionHolder ExceptionStore::exception() diff --git a/src/corelib/thread/qfutureinterface.cpp b/src/corelib/thread/qfutureinterface.cpp index 1303be10b1..e6380a8732 100644 --- a/src/corelib/thread/qfutureinterface.cpp +++ b/src/corelib/thread/qfutureinterface.cpp @@ -466,7 +466,7 @@ bool QFutureInterfaceBase::derefT() const QFutureInterfaceBasePrivate::QFutureInterfaceBasePrivate(QFutureInterfaceBase::State initialState) : refCount(1), m_progressValue(0), m_progressMinimum(0), m_progressMaximum(0), state(initialState), - manualProgress(false), m_expectedResultCount(0), runnable(0), m_pool(0) + manualProgress(false), m_expectedResultCount(0), runnable(nullptr), m_pool(nullptr) { progressTime.invalidate(); } diff --git a/src/corelib/thread/qmutex.cpp b/src/corelib/thread/qmutex.cpp index 9e52f286ee..f3883278e3 100644 --- a/src/corelib/thread/qmutex.cpp +++ b/src/corelib/thread/qmutex.cpp @@ -70,7 +70,7 @@ class QRecursiveMutexPrivate : public QMutexData { public: QRecursiveMutexPrivate() - : QMutexData(QMutex::Recursive), owner(0), count(0) {} + : QMutexData(QMutex::Recursive), owner(nullptr), count(0) {} // written to by the thread that first owns 'mutex'; // read during attempts to acquire ownership of 'mutex' from any other thread: @@ -186,7 +186,7 @@ public: */ QMutex::QMutex(RecursionMode mode) { - d_ptr.storeRelaxed(mode == Recursive ? new QRecursiveMutexPrivate : 0); + d_ptr.storeRelaxed(mode == Recursive ? new QRecursiveMutexPrivate : nullptr); } /*! @@ -799,7 +799,7 @@ inline void QRecursiveMutexPrivate::unlock() noexcept if (count > 0) { count--; } else { - owner.storeRelaxed(0); + owner.storeRelaxed(nullptr); mutex.QBasicMutex::unlock(); } } diff --git a/src/corelib/thread/qmutex_linux.cpp b/src/corelib/thread/qmutex_linux.cpp index 3270875471..72002838cf 100644 --- a/src/corelib/thread/qmutex_linux.cpp +++ b/src/corelib/thread/qmutex_linux.cpp @@ -106,7 +106,7 @@ static inline QMutexData *dummyFutexValue() } template <bool IsTimed> static inline -bool lockInternal_helper(QBasicAtomicPointer<QMutexData> &d_ptr, int timeout = -1, QElapsedTimer *elapsedTimer = 0) noexcept +bool lockInternal_helper(QBasicAtomicPointer<QMutexData> &d_ptr, int timeout = -1, QElapsedTimer *elapsedTimer = nullptr) noexcept { if (!IsTimed) timeout = -1; @@ -175,7 +175,7 @@ void QBasicMutex::unlockInternal() noexcept Q_UNUSED(d); Q_ASSERT(!isRecursive()); - d_ptr.storeRelease(0); + d_ptr.storeRelease(nullptr); futexWakeOne(d_ptr); } diff --git a/src/corelib/thread/qorderedmutexlocker_p.h b/src/corelib/thread/qorderedmutexlocker_p.h index 570c526225..83edfd5879 100644 --- a/src/corelib/thread/qorderedmutexlocker_p.h +++ b/src/corelib/thread/qorderedmutexlocker_p.h @@ -69,7 +69,7 @@ class QOrderedMutexLocker public: QOrderedMutexLocker(QBasicMutex *m1, QBasicMutex *m2) : mtx1((m1 == m2) ? m1 : (std::less<QBasicMutex *>()(m1, m2) ? m1 : m2)), - mtx2((m1 == m2) ? 0 : (std::less<QBasicMutex *>()(m1, m2) ? m2 : m1)), + mtx2((m1 == m2) ? nullptr : (std::less<QBasicMutex *>()(m1, m2) ? m2 : m1)), locked(false) { relock(); diff --git a/src/corelib/thread/qreadwritelock.cpp b/src/corelib/thread/qreadwritelock.cpp index c8463de402..8c28507d5a 100644 --- a/src/corelib/thread/qreadwritelock.cpp +++ b/src/corelib/thread/qreadwritelock.cpp @@ -227,7 +227,7 @@ bool QReadWriteLock::tryLockForRead(int timeout) return true; while (true) { - if (d == 0) { + if (d == nullptr) { if (!d_ptr.testAndSetAcquire(nullptr, dummyLockedForRead, d)) continue; return true; @@ -341,7 +341,7 @@ bool QReadWriteLock::tryLockForWrite(int timeout) return true; while (true) { - if (d == 0) { + if (d == nullptr) { if (!d_ptr.testAndSetAcquire(d, dummyLockedForWrite, d)) continue; return true; @@ -581,7 +581,7 @@ void QReadWriteLockPrivate::recursiveUnlock() if (self == currentWriter) { if (--writerCount > 0) return; - currentWriter = 0; + currentWriter = nullptr; } else { auto it = currentReaders.find(self); if (it == currentReaders.end()) { diff --git a/src/corelib/thread/qresultstore.cpp b/src/corelib/thread/qresultstore.cpp index 1b3bc20eca..0b82b938e1 100644 --- a/src/corelib/thread/qresultstore.cpp +++ b/src/corelib/thread/qresultstore.cpp @@ -192,7 +192,7 @@ int ResultStoreBase::addResults(int index, const void *results, int vectorSize, ResultItem filteredIn(results, vectorSize); insertResultItem(index, filteredIn); } - ResultItem filteredAway(0, totalCount - vectorSize); + ResultItem filteredAway(nullptr, totalCount - vectorSize); return insertResultItem(index + vectorSize, filteredAway); } } diff --git a/src/corelib/thread/qthread.cpp b/src/corelib/thread/qthread.cpp index 1248a53160..1437768f1c 100644 --- a/src/corelib/thread/qthread.cpp +++ b/src/corelib/thread/qthread.cpp @@ -59,7 +59,7 @@ QT_BEGIN_NAMESPACE QThreadData::QThreadData(int initialRefCount) : _ref(initialRefCount), loopLevel(0), scopeLevel(0), - eventDispatcher(0), + eventDispatcher(nullptr), quitNow(false), canWait(true), isAdopted(false), requiresCoreApplication(true) { // fprintf(stderr, "QThreadData %p created\n", this); @@ -399,7 +399,7 @@ QThreadPrivate::~QThreadPrivate() QThread *QThread::currentThread() { QThreadData *data = QThreadData::current(); - Q_ASSERT(data != 0); + Q_ASSERT(data != nullptr); return data->thread.loadAcquire(); } @@ -451,7 +451,7 @@ QThread::~QThread() if (d->running && !d->finished && !d->data->isAdopted) qFatal("QThread: Destroyed while thread is still running"); - d->data->thread = 0; + d->data->thread = nullptr; } } diff --git a/src/corelib/thread/qthread_unix.cpp b/src/corelib/thread/qthread_unix.cpp index efa3cb944e..727d72a334 100644 --- a/src/corelib/thread/qthread_unix.cpp +++ b/src/corelib/thread/qthread_unix.cpp @@ -109,7 +109,7 @@ Q_STATIC_ASSERT(sizeof(pthread_t) <= sizeof(Qt::HANDLE)); enum { ThreadPriorityResetFlag = 0x80000000 }; -static thread_local QThreadData *currentThreadData = 0; +static thread_local QThreadData *currentThreadData = nullptr; static pthread_once_t current_thread_data_once = PTHREAD_ONCE_INIT; static pthread_key_t current_thread_data_key; @@ -144,7 +144,7 @@ static void destroy_current_thread_data(void *p) #if defined(Q_OS_VXWORKS) (void *)1); #else - 0); + nullptr); #endif } @@ -182,8 +182,8 @@ static void set_thread_data(QThreadData *data) static void clear_thread_data() { - currentThreadData = 0; - pthread_setspecific(current_thread_data_key, 0); + currentThreadData = nullptr; + pthread_setspecific(current_thread_data_key, nullptr); } template <typename T> @@ -226,7 +226,7 @@ QThreadData *QThreadData::current(bool createIfNecessary) } QT_CATCH(...) { clear_thread_data(); data->deref(); - data = 0; + data = nullptr; QT_RETHROW; } data->deref(); @@ -294,7 +294,7 @@ static void setCurrentThreadName(const char *name) void *QThreadPrivate::start(void *arg) { #if !defined(Q_OS_ANDROID) - pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL); + pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, nullptr); #endif pthread_cleanup_push(QThreadPrivate::finish, arg); @@ -336,7 +336,7 @@ void *QThreadPrivate::start(void *arg) emit thr->started(QThread::QPrivateSignal()); #if !defined(Q_OS_ANDROID) - pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); + pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, nullptr); pthread_testcancel(); #endif thr->run(); @@ -360,7 +360,7 @@ void *QThreadPrivate::start(void *arg) // thrown. pthread_cleanup_pop(1); - return 0; + return nullptr; } void QThreadPrivate::finish(void *arg) @@ -379,13 +379,13 @@ void QThreadPrivate::finish(void *arg) void *data = &d->data->tls; locker.unlock(); emit thr->finished(QThread::QPrivateSignal()); - QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete); + QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete); QThreadStorageData::finish((void **)data); locker.relock(); QAbstractEventDispatcher *eventDispatcher = d->data->eventDispatcher.loadRelaxed(); if (eventDispatcher) { - d->data->eventDispatcher = 0; + d->data->eventDispatcher = nullptr; locker.unlock(); eventDispatcher->closingDown(); delete eventDispatcher; @@ -794,14 +794,14 @@ bool QThread::wait(QDeadlineTimer deadline) void QThread::setTerminationEnabled(bool enabled) { QThread *thr = currentThread(); - Q_ASSERT_X(thr != 0, "QThread::setTerminationEnabled()", + Q_ASSERT_X(thr != nullptr, "QThread::setTerminationEnabled()", "Current thread was not started with QThread."); Q_UNUSED(thr) #if defined(Q_OS_ANDROID) Q_UNUSED(enabled); #else - pthread_setcancelstate(enabled ? PTHREAD_CANCEL_ENABLE : PTHREAD_CANCEL_DISABLE, NULL); + pthread_setcancelstate(enabled ? PTHREAD_CANCEL_ENABLE : PTHREAD_CANCEL_DISABLE, nullptr); if (enabled) pthread_testcancel(); #endif diff --git a/src/corelib/thread/qthreadstorage.cpp b/src/corelib/thread/qthreadstorage.cpp index fdc484d2d2..464559ffa5 100644 --- a/src/corelib/thread/qthreadstorage.cpp +++ b/src/corelib/thread/qthreadstorage.cpp @@ -116,7 +116,7 @@ void **QThreadStorageData::get() const QThreadData *data = QThreadData::current(); if (!data) { qWarning("QThreadStorage::get: QThreadStorage can only be used with threads started with QThread"); - return 0; + return nullptr; } QVector<void *> &tls = data->tls; if (tls.size() <= id) @@ -128,7 +128,7 @@ void **QThreadStorageData::get() const *v, data->thread.loadRelaxed()); - return *v ? v : 0; + return *v ? v : nullptr; } void **QThreadStorageData::set(void *p) @@ -136,7 +136,7 @@ void **QThreadStorageData::set(void *p) QThreadData *data = QThreadData::current(); if (!data) { qWarning("QThreadStorage::set: QThreadStorage can only be used with threads started with QThread"); - return 0; + return nullptr; } QVector<void *> &tls = data->tls; if (tls.size() <= id) @@ -144,7 +144,7 @@ void **QThreadStorageData::set(void *p) void *&value = tls[id]; // delete any previous data - if (value != 0) { + if (value != nullptr) { DEBUG_MSG("QThreadStorageData: Deleting previous storage %d, data %p, for thread %p", id, value, @@ -156,7 +156,7 @@ void **QThreadStorageData::set(void *p) locker.unlock(); void *q = value; - value = 0; + value = nullptr; if (destructor) destructor(q); @@ -178,7 +178,7 @@ void QThreadStorageData::finish(void **p) while (!tls->isEmpty()) { void *&value = tls->last(); void *q = value; - value = 0; + value = nullptr; int i = tls->size() - 1; tls->resize(i); diff --git a/src/corelib/thread/qwaitcondition_unix.cpp b/src/corelib/thread/qwaitcondition_unix.cpp index a8dfb9999c..80f9e780e7 100644 --- a/src/corelib/thread/qwaitcondition_unix.cpp +++ b/src/corelib/thread/qwaitcondition_unix.cpp @@ -173,7 +173,7 @@ public: QWaitCondition::QWaitCondition() { d = new QWaitConditionPrivate; - report_error(pthread_mutex_init(&d->mutex, NULL), "QWaitCondition", "mutex init"); + report_error(pthread_mutex_init(&d->mutex, nullptr), "QWaitCondition", "mutex init"); qt_initialize_pthread_cond(&d->cond, "QWaitCondition"); d->waiters = d->wakeups = 0; } diff --git a/src/corelib/time/qdatetime.cpp b/src/corelib/time/qdatetime.cpp index c833c18809..979b8c9aeb 100644 --- a/src/corelib/time/qdatetime.cpp +++ b/src/corelib/time/qdatetime.cpp @@ -1769,7 +1769,7 @@ QDate QDate::fromString(const QString &string, const QString &format, QCalendar QDateTimeParser dt(QVariant::Date, QDateTimeParser::FromString, cal); // dt.setDefaultLocale(QLocale::c()); ### Qt 6 if (dt.parseFormat(format)) - dt.fromString(string, &date, 0); + dt.fromString(string, &date, nullptr); #else Q_UNUSED(string); Q_UNUSED(format); @@ -2499,7 +2499,7 @@ QTime QTime::fromString(const QString &string, const QString &format) QDateTimeParser dt(QVariant::Time, QDateTimeParser::FromString, QCalendar()); // dt.setDefaultLocale(QLocale::c()); ### Qt 6 if (dt.parseFormat(format)) - dt.fromString(string, 0, &time); + dt.fromString(string, nullptr, &time); #else Q_UNUSED(string); Q_UNUSED(format); diff --git a/src/corelib/time/qdatetimeparser.cpp b/src/corelib/time/qdatetimeparser.cpp index 2501bbaab7..a487534528 100644 --- a/src/corelib/time/qdatetimeparser.cpp +++ b/src/corelib/time/qdatetimeparser.cpp @@ -1152,7 +1152,7 @@ QDateTimeParser::scanString(const QDateTime &defaultValue, } pos += separator.size(); sectionNodes[index].pos = pos; - int *current = 0; + int *current = nullptr; const SectionNode sn = sectionNodes.at(index); ParsedSection sect; diff --git a/src/corelib/time/qtimezone.cpp b/src/corelib/time/qtimezone.cpp index 410a16e3c5..3d2078087b 100644 --- a/src/corelib/time/qtimezone.cpp +++ b/src/corelib/time/qtimezone.cpp @@ -318,7 +318,7 @@ Q_GLOBAL_STATIC(QTimeZoneSingleton, global_tz); */ QTimeZone::QTimeZone() noexcept - : d(0) + : d(nullptr) { } diff --git a/src/corelib/time/qtimezoneprivate_icu.cpp b/src/corelib/time/qtimezoneprivate_icu.cpp index 5570ce7571..8a92bbb387 100644 --- a/src/corelib/time/qtimezoneprivate_icu.cpp +++ b/src/corelib/time/qtimezoneprivate_icu.cpp @@ -273,7 +273,7 @@ static int ucalDaylightOffset(const QByteArray &id) // Create the system default time zone QIcuTimeZonePrivate::QIcuTimeZonePrivate() - : m_ucal(0) + : m_ucal(nullptr) { // TODO No ICU C API to obtain sysem tz, assume default hasn't been changed init(ucalDefaultTimeZoneId()); @@ -281,7 +281,7 @@ QIcuTimeZonePrivate::QIcuTimeZonePrivate() // Create a named time zone QIcuTimeZonePrivate::QIcuTimeZonePrivate(const QByteArray &ianaId) - : m_ucal(0) + : m_ucal(nullptr) { // Need to check validity here as ICu will create a GMT tz if name is invalid if (availableTimeZoneIds().contains(ianaId)) @@ -289,14 +289,14 @@ QIcuTimeZonePrivate::QIcuTimeZonePrivate(const QByteArray &ianaId) } QIcuTimeZonePrivate::QIcuTimeZonePrivate(const QIcuTimeZonePrivate &other) - : QTimeZonePrivate(other), m_ucal(0) + : QTimeZonePrivate(other), m_ucal(nullptr) { // Clone the ucal so we don't close the shared object UErrorCode status = U_ZERO_ERROR; m_ucal = ucal_clone(other.m_ucal, &status); if (!U_SUCCESS(status)) { m_id.clear(); - m_ucal = 0; + m_ucal = nullptr; } } @@ -322,7 +322,7 @@ void QIcuTimeZonePrivate::init(const QByteArray &ianaId) if (!U_SUCCESS(status)) { m_id.clear(); - m_ucal = 0; + m_ucal = nullptr; } } @@ -493,7 +493,7 @@ QList<QByteArray> QIcuTimeZonePrivate::availableTimeZoneIds(int offsetFromUtc) c // TODO Available directly in C++ api but not C api, from 4.8 onwards new filter method works #if U_ICU_VERSION_MAJOR_NUM >= 49 || (U_ICU_VERSION_MAJOR_NUM == 4 && U_ICU_VERSION_MINOR_NUM == 8) UErrorCode status = U_ZERO_ERROR; - UEnumeration *uenum = ucal_openTimeZoneIDEnumeration(UCAL_ZONE_TYPE_ANY, 0, + UEnumeration *uenum = ucal_openTimeZoneIDEnumeration(UCAL_ZONE_TYPE_ANY, nullptr, &offsetFromUtc, &status); QList<QByteArray> result; if (U_SUCCESS(status)) diff --git a/src/corelib/time/qtimezoneprivate_tz.cpp b/src/corelib/time/qtimezoneprivate_tz.cpp index 3c2695a789..5e55c6897d 100644 --- a/src/corelib/time/qtimezoneprivate_tz.cpp +++ b/src/corelib/time/qtimezoneprivate_tz.cpp @@ -512,7 +512,7 @@ PosixZone PosixZone::parse(const char *&pos, const char *end) if (zoneEnd < end && (zoneEnd[0] == '+' || zoneEnd[0] == '-')) ++zoneEnd; while (zoneEnd < end) { - if (strchr(offsetChars, char(*zoneEnd)) == NULL) + if (strchr(offsetChars, char(*zoneEnd)) == nullptr) break; ++zoneEnd; } diff --git a/src/corelib/tools/qarraydata.cpp b/src/corelib/tools/qarraydata.cpp index 4c9324255f..00f6dfe6ef 100644 --- a/src/corelib/tools/qarraydata.cpp +++ b/src/corelib/tools/qarraydata.cpp @@ -276,7 +276,7 @@ void QArrayData::deallocate(QArrayData *data, size_t objectSize, && !(alignment & (alignment - 1))); Q_UNUSED(objectSize) Q_UNUSED(alignment) - Q_ASSERT_X(data == 0 || !data->isStatic(), "QArrayData::deallocate", + Q_ASSERT_X(data == nullptr || !data->isStatic(), "QArrayData::deallocate", "Static data cannot be deleted"); ::free(data); } diff --git a/src/corelib/tools/qeasingcurve.cpp b/src/corelib/tools/qeasingcurve.cpp index d7f69d3e0a..0ec51aa4d3 100644 --- a/src/corelib/tools/qeasingcurve.cpp +++ b/src/corelib/tools/qeasingcurve.cpp @@ -443,12 +443,12 @@ class QEasingCurvePrivate public: QEasingCurvePrivate() : type(QEasingCurve::Linear), - config(0), + config(nullptr), func(&easeNone) { } QEasingCurvePrivate(const QEasingCurvePrivate &other) : type(other.type), - config(other.config ? other.config->copy() : 0), + config(other.config ? other.config->copy() : nullptr), func(other.func) { } ~QEasingCurvePrivate() { delete config; } @@ -590,7 +590,7 @@ struct BezierEase : public QEasingCurveFunction if (!(x < 1)) return 1; - SingleCubicBezier *singleCubicBezier = 0; + SingleCubicBezier *singleCubicBezier = nullptr; getBezierSegment(singleCubicBezier, x); return evaluateSegmentForY(*singleCubicBezier, findTForX(*singleCubicBezier, x)); @@ -1097,7 +1097,7 @@ static QEasingCurve::EasingFunction curveToFunc(QEasingCurve::Type curve) case QEasingCurve::CosineCurve: return &easeCosineCurve; default: - return 0; + return nullptr; }; } @@ -1127,7 +1127,7 @@ static QEasingCurveFunction *curveToFunctionObject(QEasingCurve::Type type) return new QEasingCurveFunction(type, qreal(0.3), qreal(1.0), qreal(1.70158)); } - return 0; + return nullptr; } /*! @@ -1417,7 +1417,7 @@ void QEasingCurvePrivate::setType_helper(QEasingCurve::Type newType) tcbPoints = std::move(config->_tcbPoints); delete config; - config = 0; + config = nullptr; } if (isConfigFunction(newType) || (amp != -1.0) || (period != -1.0) || (overshoot != -1.0) || @@ -1431,11 +1431,11 @@ void QEasingCurvePrivate::setType_helper(QEasingCurve::Type newType) config->_o = overshoot; config->_bezierCurves = std::move(bezierCurves); config->_tcbPoints = std::move(tcbPoints); - func = 0; + func = nullptr; } else if (newType != QEasingCurve::Custom) { func = curveToFunc(newType); } - Q_ASSERT((func == 0) == (config != 0)); + Q_ASSERT((func == nullptr) == (config != nullptr)); type = newType; } @@ -1482,7 +1482,7 @@ void QEasingCurve::setCustomType(EasingFunction func) */ QEasingCurve::EasingFunction QEasingCurve::customType() const { - return d_ptr->type == Custom ? d_ptr->func : 0; + return d_ptr->type == Custom ? d_ptr->func : nullptr; } /*! diff --git a/src/corelib/tools/qhash.cpp b/src/corelib/tools/qhash.cpp index a53d6db997..dcac91778f 100644 --- a/src/corelib/tools/qhash.cpp +++ b/src/corelib/tools/qhash.cpp @@ -1807,6 +1807,18 @@ uint qHash(long double key, uint seed) noexcept \sa insertMulti() */ +/*! \fn template <class Key, class T> void QHash<Key, T>::insert(const QHash &other) + \since 5.15 + + Inserts all the items in the \a other hash into this hash. + + If a key is common to both hashes, its value will be replaced with the + value stored in \a other. + + \note If \a other contains multiple entries with the same key then the + final value of the key is undefined. +*/ + /*! \fn template <class Key, class T> QHash<Key, T>::iterator QHash<Key, T>::insertMulti(const Key &key, const T &value) Inserts a new item with the \a key and a value of \a value. diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h index 55702183fe..84e6b0f944 100644 --- a/src/corelib/tools/qhash.h +++ b/src/corelib/tools/qhash.h @@ -507,6 +507,7 @@ public: const_iterator find(const Key &key) const; const_iterator constFind(const Key &key) const; iterator insert(const Key &key, const T &value); + void insert(const QHash &hash); iterator insertMulti(const Key &key, const T &value); QHash &unite(const QHash &other); @@ -822,6 +823,31 @@ Q_INLINE_TEMPLATE typename QHash<Key, T>::iterator QHash<Key, T>::insert(const K } template <class Key, class T> +Q_INLINE_TEMPLATE void QHash<Key, T>::insert(const QHash &hash) +{ + if (d == hash.d) + return; + + detach(); + + QHashData::Node *i = hash.d->firstNode(); + QHashData::Node *end = reinterpret_cast<QHashData::Node *>(hash.e); + while (i != end) { + Node *n = concrete(i); + Node **node = findNode(n->key, n->h); + if (*node == e) { + if (d->willGrow()) + node = findNode(n->key, n->h); + createNode(n->h, n->key, n->value, node); + } else { + if (!std::is_same<T, QHashDummyValue>::value) + (*node)->value = n->value; + } + i = QHashData::nextNode(i); + } +} + +template <class Key, class T> Q_INLINE_TEMPLATE typename QHash<Key, T>::iterator QHash<Key, T>::insertMulti(const Key &akey, const T &avalue) { |