英文:
QVector of QStrings, how to join?
问题
由于多种原因,例如mid
方法,我更愿意使用QVector<QString>
而不是QStringList
。我所面临的唯一不便是,我有时也需要将元素连接成一个单独的QString
。
在QStringList
中,这很容易,你可以简单地使用join(',')
,但当使用QVector<QString>
时,如何做到这一点而不编写专用函数呢?是否有类似.map()
方法?
英文:
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?
答案1
得分: 1
我不知道你所说的 "several reasons" 应该是什么;至少在所有支持的 Qt 版本中,QStringList
存在 mid
方法。
更多细节:
- Qt5:
Qt 5.15 LTS 版本有一个mid
方法用于QStringList
,是 Qt5 的最后一个受支持版本,标准支持将于 2023 年 5 月底结束,订阅支持将在 2025 年结束。 - Qt6:
QVector
和QList
现在是完全相同的类型。由此可知,QStringList
是QVector<QString>
。
结论:仅仅在 3 个月内(如果你是订阅用户,那将会是 27 个月)提到 mid
方法的话,实际上已经存在。
英文:
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:<br/>
Qt 5.15 LTS has amid
method forQStringList
, 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:<br/>
QVector
andQList
are now the exact same type. By extension, aQStringList
is aQVector<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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论