Search code examples
qtqvectorqstringlist

QVector of QStrings, how to join?


Due to several reasons, e.g. the mid method, I would prefer to use a QVector<QString> over QStringList. The only downside I face is that I also have to join the elements from time to time to a single QString.

In QStringlist that is easy, you can simply use join(','), but how to do that when using a QVector<QString> without writing a dedicated function? Is there something like a .map() method?


Solution

  • I do not know what your "several reasons" were supposed to be; at the very least the mid method exists for QStringList in all the supported version of Qt.

    More details:

    • Qt5:
      Qt 5.15 LTS has a mid method for QStringList, is the last supported version of Qt5, and goes out of standard support by end of May 2023, out of subscribers' support in 2025.
    • Qt6:
      QVector and QList are now the exact same type. By extension, a QStringList is a QVector<QString>.

    Conclusion: your question will not make sense in just 3 months (27 months if you are a subscriber) and if just talking about a mid method, it was in fact already present.