Skip to content

Commit c2f4e5e

Browse files
committed
qt, refactor: Fix 'split is deprecated' warnings
1 parent 8e12d69 commit c2f4e5e

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

src/qt/guiutil.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,27 @@ namespace GUIUtil
320320
bool HasPixmap(const QLabel* label);
321321
QImage GetImage(const QLabel* label);
322322

323+
/**
324+
* Splits the string into substrings wherever separator occurs, and returns
325+
* the list of those strings. Empty strings do not appear in the result.
326+
*
327+
* QString::split() signature differs in different Qt versions:
328+
* - QString::SplitBehavior is deprecated since Qt 5.15
329+
* - Qt::SplitBehavior was introduced in Qt 5.14
330+
* If {QString|Qt}::SkipEmptyParts behavior is required, use this
331+
* function instead of QString::split().
332+
*/
333+
template <typename SeparatorType>
334+
QStringList SplitSkipEmptyParts(const QString& string, const SeparatorType& separator)
335+
{
336+
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
337+
return string.split(separator, Qt::SkipEmptyParts);
338+
#else
339+
return string.split(separator, QString::SkipEmptyParts);
340+
#endif
341+
}
342+
343+
323344
} // namespace GUIUtil
324345

325346
#endif // BITCOIN_QT_GUIUTIL_H

src/qt/optionsmodel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ static ProxySetting GetProxySetting(QSettings &settings, const QString &name)
219219
return default_val;
220220
}
221221
// contains IP at index 0 and port at index 1
222-
QStringList ip_port = settings.value(name).toString().split(":", QString::SkipEmptyParts);
222+
QStringList ip_port = GUIUtil::SplitSkipEmptyParts(settings.value(name).toString(), ":");
223223
if (ip_port.size() == 2) {
224224
return {true, ip_port.at(0), ip_port.at(1)};
225225
} else { // Invalid: return default

src/qt/transactionview.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ void TransactionView::setModel(WalletModel *_model)
237237
if (_model->getOptionsModel())
238238
{
239239
// Add third party transaction URLs to context menu
240-
QStringList listUrls = _model->getOptionsModel()->getThirdPartyTxUrls().split("|", QString::SkipEmptyParts);
240+
QStringList listUrls = GUIUtil::SplitSkipEmptyParts(_model->getOptionsModel()->getThirdPartyTxUrls(), "|");
241241
for (int i = 0; i < listUrls.size(); ++i)
242242
{
243243
QString url = listUrls[i].trimmed();

0 commit comments

Comments
 (0)