Skip to content

Commit

Permalink
Merge #2264: [GUI] fix 'split is deprecated' warnings
Browse files Browse the repository at this point in the history
2c655b1 [GUI] fix 'split is deprecated' warnings (Fuzzbawls)

Pull request description:

  Qt 5.15 has deprecated QString::SplitBehavior, this provides a
  work-around that is still compatible with our baseline Qt version.

ACKs for top commit:
  random-zebra:
    utACK 2c655b1
  furszy:
    ACK 2c655b1

Tree-SHA512: 963d7211301a5690b5119a3ddf0296658700f2265d75c51aa372dd65734ed724c22d8295c704ae769ed8b1a4205501039c42046b843307d131db2664c2a6f9da
  • Loading branch information
furszy committed Apr 6, 2021
2 parents daf8027 + 2c655b1 commit a4da3a8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
20 changes: 20 additions & 0 deletions src/qt/guiutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,26 @@ QString formatTimeOffset(int64_t nTimeOffset);
typedef QProgressBar ProgressBar;
#endif

/**
* Splits the string into substrings wherever separator occurs, and returns
* the list of those strings. Empty strings do not appear in the result.
*
* QString::split() signature differs in different Qt versions:
* - QString::SplitBehavior is deprecated since Qt 5.15
* - Qt::SplitBehavior was introduced in Qt 5.14
* If {QString|Qt}::SkipEmptyParts behavior is required, use this
* function instead of QString::split().
*/
template <typename SeparatorType>
QStringList SplitSkipEmptyParts(const QString& string, const SeparatorType& separator)
{
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
return string.split(separator, Qt::SkipEmptyParts);
#else
return string.split(separator, QString::SkipEmptyParts);
#endif
}

} // namespace GUIUtil

#endif // BITCOIN_QT_GUIUTIL_H
8 changes: 4 additions & 4 deletions src/qt/optionsmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,12 +247,12 @@ QVariant OptionsModel::data(const QModelIndex& index, int role) const
return settings.value("fUseProxy", false);
case ProxyIP: {
// contains IP at index 0 and port at index 1
QStringList strlIpPort = settings.value("addrProxy").toString().split(":", QString::SkipEmptyParts);
QStringList strlIpPort = GUIUtil::SplitSkipEmptyParts(settings.value("addrProxy").toString(), ":");
return strlIpPort.at(0);
}
case ProxyPort: {
// contains IP at index 0 and port at index 1
QStringList strlIpPort = settings.value("addrProxy").toString().split(":", QString::SkipEmptyParts);
QStringList strlIpPort = GUIUtil::SplitSkipEmptyParts(settings.value("addrProxy").toString(), ":");
return strlIpPort.at(1);
}

Expand Down Expand Up @@ -342,7 +342,7 @@ bool OptionsModel::setData(const QModelIndex& index, const QVariant& value, int
break;
case ProxyIP: {
// contains current IP at index 0 and current port at index 1
QStringList strlIpPort = settings.value("addrProxy").toString().split(":", QString::SkipEmptyParts);
QStringList strlIpPort = GUIUtil::SplitSkipEmptyParts(settings.value("addrProxy").toString(), ":");
// if that key doesn't exist or has a changed IP
if (!settings.contains("addrProxy") || strlIpPort.at(0) != value.toString()) {
// construct new value from new IP and current port
Expand All @@ -353,7 +353,7 @@ bool OptionsModel::setData(const QModelIndex& index, const QVariant& value, int
} break;
case ProxyPort: {
// contains current IP at index 0 and current port at index 1
QStringList strlIpPort = settings.value("addrProxy").toString().split(":", QString::SkipEmptyParts);
QStringList strlIpPort = GUIUtil::SplitSkipEmptyParts(settings.value("addrProxy").toString(), ":");
// if that key doesn't exist or has a changed port
if (!settings.contains("addrProxy") || strlIpPort.at(1) != value.toString()) {
// construct new value from current IP and new port
Expand Down

0 comments on commit a4da3a8

Please sign in to comment.