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

macOS - QString doesn't perform properly



  • Hi,
    I have a bit of an issue with QString - its split() and section() methods always return empty QStringList() ro QString(). Same code ported to Windows works.
    Any hints please?

    Edit - code sample:

     QString formatter2=settings.value("archivedLabels").toString().section('_',0);
    

    or

     QString formatter2=settings.value("archivedLabels").toString().split('_').at(0);
    

    I also tried to replace QString formatter2 with QStringList() making this

    QStringList temp=settings.value("archivedLabels").toString().split('_');
    

    and got empty QStringList.


  • Moderators

    @artwaw can't confirm that, you'll have to show us the code, that you're using

    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
    
        QString testString("RM_dd-MM-yyyy");
    
        QStringList splittedList1 = testString.split(QChar('-'));
        QStringList splittedList2 = testString.split(QChar('_'));
    
        QString section1 = testString.section(QChar('-'), 0,0);
        QString section2 = testString.section(QChar('-'), 1,1);
    
        qDebug() << splittedList1 << endl
                 << splittedList2 << endl
                 << section1 << section2;
    
        return  a.exec();
    }
    
    

    results in:
    7fe266a3-7048-44f8-973d-13809b6bb609-image.png


  • Moderators

    @artwaw
    can you provide an example string?



  • @J-Hilk RM_dd-MM-yyyy


  • Moderators

    @artwaw can't confirm that, you'll have to show us the code, that you're using

    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
    
        QString testString("RM_dd-MM-yyyy");
    
        QStringList splittedList1 = testString.split(QChar('-'));
        QStringList splittedList2 = testString.split(QChar('_'));
    
        QString section1 = testString.section(QChar('-'), 0,0);
        QString section2 = testString.section(QChar('-'), 1,1);
    
        qDebug() << splittedList1 << endl
                 << splittedList2 << endl
                 << section1 << section2;
    
        return  a.exec();
    }
    
    

    results in:
    7fe266a3-7048-44f8-973d-13809b6bb609-image.png



  • @J-Hilk Then it must be me or something in my setup. Thank you!


Log in to reply