Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Multiple warning messages when using split() in Qt 5.15.2



  • Hello All,

    How to supress the warnings when QString::split() API is used. Please find the sample code below

    QString str = "10:20";
    QStringList liststr = str.split(':', QString::SkipEmptyParts);
    int value1 = liststr.at(1).toUInt();
    int value2 = liststr.at(0).toUInt();

    The warnings are:
    'split' is deprecated: Use Qt::SplitBehavior variant instead
    qstring.h:609:23: note: 'split' has been explicitly marked deprecated here
    qglobal.h:374:45: note: expanded from macro 'QT_DEPRECATED_VERSION_X_5_15'
    qglobal.h:294:33: note: expanded from macro 'QT_DEPRECATED_X'
    qcompilerdetection.h:675:55: note: expanded from macro 'Q_DECL_DEPRECATED_X'

    How to resolve this ??



  • Yeah, I just looked at the doc...usually when Qt deprecates something, it suggests an alternative, but evidently not in this case. You may have to copy an online example, and do it yourself. This example looks reasonable. Good luck.


  • Moderators

    The warning sugests you use Qt::SkipEmptyParts:

    QStringList liststr = str.split(':', Qt::SkipEmptyParts);
    

    This should work from Qt 5.14 onwards.

    If you (for whatever reason) just want to silence the warning, set https://doc.qt.io/qt-5/qtglobal.html#QT_DISABLE_DEPRECATED_BEFORE to an older version ...



  • @kkoehne ah, after reading your reply, the error message makes (a little) more sense.

    That's not a great error message though...both it and the docs section talking about the deprecation could use some rewording, IMO.


Log in to reply