QVector中的QString,如何拼接?

huangapple go评论67阅读模式
英文:

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:
    QVectorQList 现在是完全相同的类型。由此可知,QStringListQVector<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 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:<br/>
    QVector and QList are now the exact same type. By extension, a QStringList is a QVector&lt;QString&gt;.

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.

huangapple
  • 本文由 发表于 2023年2月24日 07:21:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/75551289.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定