Deprecate QString::null
It's a Qt 3 compatibility vehicle, and as such inherits the now-alien property to distinguish empty and null strings. Particularly worrisome is the following asymmetry: QString("") == QString::null // false QString("") == QString(QString::null) // true Instead of fixing this behavior, recognize that people might use it as a weird way to call isNull(), albeit one that once was idiomatic, and simply deprecate everything that deals with QString::null. [ChangeLog][QtCore][QString] QString::null is now deprecated. When used to construct a QString, use QString() instead. When used to compare to a QString, replace with QString::isNull(). Change-Id: I9f7e84a92522c75666da15f49324c500ae93af42 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Anton Kudryavtsev <antkudr@mail.ru>
This commit is contained in:
parent
63a39927a0
commit
75f5e2bef2
@ -779,7 +779,9 @@ inline char qToLower(char ch)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#if QT_DEPRECATED_SINCE(5, 9)
|
||||||
const QString::Null QString::null = { };
|
const QString::Null QString::null = { };
|
||||||
|
#endif
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\macro QT_RESTRICTED_CAST_FROM_ASCII
|
\macro QT_RESTRICTED_CAST_FROM_ASCII
|
||||||
|
@ -770,10 +770,13 @@ public:
|
|||||||
NSString *toNSString() const Q_DECL_NS_RETURNS_AUTORELEASED;
|
NSString *toNSString() const Q_DECL_NS_RETURNS_AUTORELEASED;
|
||||||
#endif
|
#endif
|
||||||
// compatibility
|
// compatibility
|
||||||
|
#if QT_DEPRECATED_SINCE(5, 9)
|
||||||
struct Null { };
|
struct Null { };
|
||||||
|
QT_DEPRECATED_X("use QString()")
|
||||||
static const Null null;
|
static const Null null;
|
||||||
inline QString(const Null &): d(Data::sharedNull()) {}
|
inline QString(const Null &): d(Data::sharedNull()) {}
|
||||||
inline QString &operator=(const Null &) { *this = QString(); return *this; }
|
inline QString &operator=(const Null &) { *this = QString(); return *this; }
|
||||||
|
#endif
|
||||||
inline bool isNull() const { return d == Data::sharedNull(); }
|
inline bool isNull() const { return d == Data::sharedNull(); }
|
||||||
|
|
||||||
|
|
||||||
@ -1134,13 +1137,18 @@ inline bool QString::contains(QLatin1String s, Qt::CaseSensitivity cs) const
|
|||||||
inline bool QString::contains(QChar c, Qt::CaseSensitivity cs) const
|
inline bool QString::contains(QChar c, Qt::CaseSensitivity cs) const
|
||||||
{ return indexOf(c, 0, cs) != -1; }
|
{ return indexOf(c, 0, cs) != -1; }
|
||||||
|
|
||||||
|
#if QT_DEPRECATED_SINCE(5, 9)
|
||||||
inline bool operator==(QString::Null, QString::Null) { return true; }
|
inline bool operator==(QString::Null, QString::Null) { return true; }
|
||||||
|
QT_DEPRECATED_X("use QString::isNull()")
|
||||||
inline bool operator==(QString::Null, const QString &s) { return s.isNull(); }
|
inline bool operator==(QString::Null, const QString &s) { return s.isNull(); }
|
||||||
|
QT_DEPRECATED_X("use QString::isNull()")
|
||||||
inline bool operator==(const QString &s, QString::Null) { return s.isNull(); }
|
inline bool operator==(const QString &s, QString::Null) { return s.isNull(); }
|
||||||
inline bool operator!=(QString::Null, QString::Null) { return false; }
|
inline bool operator!=(QString::Null, QString::Null) { return false; }
|
||||||
|
QT_DEPRECATED_X("use !QString::isNull()")
|
||||||
inline bool operator!=(QString::Null, const QString &s) { return !s.isNull(); }
|
inline bool operator!=(QString::Null, const QString &s) { return !s.isNull(); }
|
||||||
|
QT_DEPRECATED_X("use !QString::isNull()")
|
||||||
inline bool operator!=(const QString &s, QString::Null) { return !s.isNull(); }
|
inline bool operator!=(const QString &s, QString::Null) { return !s.isNull(); }
|
||||||
|
#endif
|
||||||
|
|
||||||
inline bool operator==(QLatin1String s1, QLatin1String s2) Q_DECL_NOTHROW
|
inline bool operator==(QLatin1String s1, QLatin1String s2) Q_DECL_NOTHROW
|
||||||
{ return s1.size() == s2.size() && (!s1.size() || !memcmp(s1.latin1(), s2.latin1(), s1.size())); }
|
{ return s1.size() == s2.size() && (!s1.size() || !memcmp(s1.latin1(), s2.latin1(), s1.size())); }
|
||||||
|
@ -519,7 +519,7 @@ QString QAccessibleDisplay::imageDescription() const
|
|||||||
#ifndef QT_NO_TOOLTIP
|
#ifndef QT_NO_TOOLTIP
|
||||||
return widget()->toolTip();
|
return widget()->toolTip();
|
||||||
#else
|
#else
|
||||||
return QString::null;
|
return QString();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1863,7 +1863,7 @@ void QMdiSubWindowPrivate::removeButtonsFromMenuBar()
|
|||||||
topLevelWindow->removeEventFilter(q);
|
topLevelWindow->removeEventFilter(q);
|
||||||
if (baseWidget && !drawTitleBarWhenMaximized())
|
if (baseWidget && !drawTitleBarWhenMaximized())
|
||||||
topLevelWindow->setWindowModified(false);
|
topLevelWindow->setWindowModified(false);
|
||||||
originalTitle = QString::null;
|
originalTitle.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // QT_NO_MENUBAR
|
#endif // QT_NO_MENUBAR
|
||||||
@ -2769,7 +2769,7 @@ bool QMdiSubWindow::eventFilter(QObject *object, QEvent *event)
|
|||||||
#ifndef QT_NO_MENUBAR
|
#ifndef QT_NO_MENUBAR
|
||||||
} else if (maximizedButtonsWidget() && d->controlContainer->menuBar() && d->controlContainer->menuBar()
|
} else if (maximizedButtonsWidget() && d->controlContainer->menuBar() && d->controlContainer->menuBar()
|
||||||
->cornerWidget(Qt::TopRightCorner) == maximizedButtonsWidget()) {
|
->cornerWidget(Qt::TopRightCorner) == maximizedButtonsWidget()) {
|
||||||
d->originalTitle = QString::null;
|
d->originalTitle.clear();
|
||||||
if (d->baseWidget && d->baseWidget->windowTitle() == windowTitle())
|
if (d->baseWidget && d->baseWidget->windowTitle() == windowTitle())
|
||||||
d->updateWindowTitle(true);
|
d->updateWindowTitle(true);
|
||||||
else
|
else
|
||||||
|
@ -1684,7 +1684,7 @@ void tst_QFile::isSequential()
|
|||||||
|
|
||||||
void tst_QFile::encodeName()
|
void tst_QFile::encodeName()
|
||||||
{
|
{
|
||||||
QCOMPARE(QFile::encodeName(QString::null), QByteArray());
|
QCOMPARE(QFile::encodeName(QString()), QByteArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_QFile::truncate()
|
void tst_QFile::truncate()
|
||||||
|
@ -3818,7 +3818,7 @@ void tst_QString::startsWith()
|
|||||||
QVERIFY( !a.startsWith(QLatin1Char('x')) );
|
QVERIFY( !a.startsWith(QLatin1Char('x')) );
|
||||||
QVERIFY( !a.startsWith(QChar()) );
|
QVERIFY( !a.startsWith(QChar()) );
|
||||||
|
|
||||||
a = QString::null;
|
a = QString();
|
||||||
QVERIFY( !a.startsWith("") );
|
QVERIFY( !a.startsWith("") );
|
||||||
QVERIFY( a.startsWith(QString::null) );
|
QVERIFY( a.startsWith(QString::null) );
|
||||||
QVERIFY( !a.startsWith("ABC") );
|
QVERIFY( !a.startsWith("ABC") );
|
||||||
@ -3928,7 +3928,7 @@ void tst_QString::endsWith()
|
|||||||
QVERIFY( a.endsWith(QLatin1String(0)) );
|
QVERIFY( a.endsWith(QLatin1String(0)) );
|
||||||
QVERIFY( !a.endsWith(QLatin1String("ABC")) );
|
QVERIFY( !a.endsWith(QLatin1String("ABC")) );
|
||||||
|
|
||||||
a = QString::null;
|
a = QString();
|
||||||
QVERIFY( !a.endsWith("") );
|
QVERIFY( !a.endsWith("") );
|
||||||
QVERIFY( a.endsWith(QString::null) );
|
QVERIFY( a.endsWith(QString::null) );
|
||||||
QVERIFY( !a.endsWith("ABC") );
|
QVERIFY( !a.endsWith("ABC") );
|
||||||
|
@ -124,7 +124,7 @@ protected slots:
|
|||||||
private:
|
private:
|
||||||
QFtp *newFtp();
|
QFtp *newFtp();
|
||||||
void addCommand( QFtp::Command, int );
|
void addCommand( QFtp::Command, int );
|
||||||
bool fileExists( const QString &host, quint16 port, const QString &user, const QString &password, const QString &file, const QString &cdDir = QString::null );
|
bool fileExists( const QString &host, quint16 port, const QString &user, const QString &password, const QString &file, const QString &cdDir = QString() );
|
||||||
bool dirExists( const QString &host, quint16 port, const QString &user, const QString &password, const QString &cdDir, const QString &dirToCreate );
|
bool dirExists( const QString &host, quint16 port, const QString &user, const QString &password, const QString &cdDir, const QString &dirToCreate );
|
||||||
|
|
||||||
void renameInit( const QString &host, const QString &user, const QString &password, const QString &createFile );
|
void renameInit( const QString &host, const QString &user, const QString &password, const QString &createFile );
|
||||||
|
@ -2191,7 +2191,7 @@ void tst_QSqlDatabase::sqlStatementUseIsNull_189093()
|
|||||||
CHECK_DATABASE(db);
|
CHECK_DATABASE(db);
|
||||||
|
|
||||||
// select a record with NULL value
|
// select a record with NULL value
|
||||||
QSqlQuery q(QString::null, db);
|
QSqlQuery q(QString(), db);
|
||||||
QVERIFY_SQL(q, exec("select * from " + qTableName("qtest", __FILE__, db) + " where id = 4"));
|
QVERIFY_SQL(q, exec("select * from " + qTableName("qtest", __FILE__, db) + " where id = 4"));
|
||||||
QVERIFY_SQL(q, next());
|
QVERIFY_SQL(q, next());
|
||||||
|
|
||||||
|
@ -701,14 +701,14 @@ void tst_QShortcut::disabledItems()
|
|||||||
sendKeyEvents( Qt::CTRL+Qt::Key_M, 0 );
|
sendKeyEvents( Qt::CTRL+Qt::Key_M, 0 );
|
||||||
QCOMPARE( currentResult, NoResult );
|
QCOMPARE( currentResult, NoResult );
|
||||||
if (over_330)
|
if (over_330)
|
||||||
QCOMPARE( sbText, QString::null );
|
QCOMPARE( sbText, QString() );
|
||||||
|
|
||||||
currentResult = NoResult;
|
currentResult = NoResult;
|
||||||
sendKeyEvents( Qt::CTRL+Qt::Key_K, 0 );
|
sendKeyEvents( Qt::CTRL+Qt::Key_K, 0 );
|
||||||
sendKeyEvents( Qt::CTRL+Qt::Key_L, 0 );
|
sendKeyEvents( Qt::CTRL+Qt::Key_L, 0 );
|
||||||
QCOMPARE( currentResult, Slot1Triggered );
|
QCOMPARE( currentResult, Slot1Triggered );
|
||||||
if (over_330)
|
if (over_330)
|
||||||
QCOMPARE( sbText, QString::null );
|
QCOMPARE( sbText, QString() );
|
||||||
#endif
|
#endif
|
||||||
clearAllShortcuts();
|
clearAllShortcuts();
|
||||||
cut1 = 0;
|
cut1 = 0;
|
||||||
|
@ -713,8 +713,8 @@ void tst_QLineEdit::clearInputMask()
|
|||||||
{
|
{
|
||||||
QLineEdit *testWidget = ensureTestWidget();
|
QLineEdit *testWidget = ensureTestWidget();
|
||||||
testWidget->setInputMask("000.000.000.000");
|
testWidget->setInputMask("000.000.000.000");
|
||||||
QVERIFY(testWidget->inputMask() != QString::null);
|
QVERIFY(!testWidget->inputMask().isNull());
|
||||||
testWidget->setInputMask(QString::null);
|
testWidget->setInputMask(QString());
|
||||||
QCOMPARE(testWidget->inputMask(), QString());
|
QCOMPARE(testWidget->inputMask(), QString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2277,7 +2277,7 @@ void tst_QLineEdit::textChangedAndTextEdited()
|
|||||||
|
|
||||||
changed_count = 0;
|
changed_count = 0;
|
||||||
edited_count = 0;
|
edited_count = 0;
|
||||||
changed_string = QString::null;
|
changed_string.clear();
|
||||||
|
|
||||||
testWidget->setText("foo");
|
testWidget->setText("foo");
|
||||||
QCOMPARE(changed_count, 1);
|
QCOMPARE(changed_count, 1);
|
||||||
@ -2286,7 +2286,7 @@ void tst_QLineEdit::textChangedAndTextEdited()
|
|||||||
|
|
||||||
changed_count = 0;
|
changed_count = 0;
|
||||||
edited_count = 0;
|
edited_count = 0;
|
||||||
changed_string = QString::null;
|
changed_string.clear();
|
||||||
|
|
||||||
testWidget->setText("");
|
testWidget->setText("");
|
||||||
QCOMPARE(changed_count, 1);
|
QCOMPARE(changed_count, 1);
|
||||||
@ -3108,7 +3108,7 @@ void tst_QLineEdit::maxLengthAndInputMask()
|
|||||||
QVERIFY(testWidget->inputMask().isNull());
|
QVERIFY(testWidget->inputMask().isNull());
|
||||||
testWidget->setMaxLength(10);
|
testWidget->setMaxLength(10);
|
||||||
QCOMPARE(testWidget->maxLength(), 10);
|
QCOMPARE(testWidget->maxLength(), 10);
|
||||||
testWidget->setInputMask(QString::null);
|
testWidget->setInputMask(QString());
|
||||||
QVERIFY(testWidget->inputMask().isNull());
|
QVERIFY(testWidget->inputMask().isNull());
|
||||||
QCOMPARE(testWidget->maxLength(), 10);
|
QCOMPARE(testWidget->maxLength(), 10);
|
||||||
}
|
}
|
||||||
|
@ -362,7 +362,7 @@ void tst_QPlainTextEdit::emptyAppend()
|
|||||||
{
|
{
|
||||||
ed->appendPlainText("Blah");
|
ed->appendPlainText("Blah");
|
||||||
QCOMPARE(blockCount(), 1);
|
QCOMPARE(blockCount(), 1);
|
||||||
ed->appendPlainText(QString::null);
|
ed->appendPlainText(QString());
|
||||||
QCOMPARE(blockCount(), 2);
|
QCOMPARE(blockCount(), 2);
|
||||||
ed->appendPlainText(QString(" "));
|
ed->appendPlainText(QString(" "));
|
||||||
QCOMPARE(blockCount(), 3);
|
QCOMPARE(blockCount(), 3);
|
||||||
|
@ -676,7 +676,7 @@ void tst_QTextEdit::emptyAppend()
|
|||||||
{
|
{
|
||||||
ed->append("Blah");
|
ed->append("Blah");
|
||||||
QCOMPARE(blockCount(), 1);
|
QCOMPARE(blockCount(), 1);
|
||||||
ed->append(QString::null);
|
ed->append(QString());
|
||||||
QCOMPARE(blockCount(), 2);
|
QCOMPARE(blockCount(), 2);
|
||||||
ed->append(QString(" "));
|
ed->append(QString(" "));
|
||||||
QCOMPARE(blockCount(), 3);
|
QCOMPARE(blockCount(), 3);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user