0
点赞
收藏
分享

微信扫一扫

TortoiseSVN 报错:The server unexpectedly closed the connetion

早安地球 03-13 14:00 阅读 2

在qt中,要将QHash中的数据有序地放入到QList中,首先要明白:

我们可以遍历QHash中的键值对,并将其按照键的顺序或值的大小插入到QList中,直接用for循环即可。
 

#include <QCoreApplication>
#include <QHash>
#include <QList>
#include <QDebug>

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    QHash<int, QString> hash;
    hash.insert(3, "Three");
    hash.insert(1, "One");
    hash.insert(2, "Two");

    QList<QString> list;
    foreach (int key, hash.keys()) {
        list.append(hash.value(key));
    }

    foreach (QString value, list) {
        qDebug() << value;
    }

    return a.exec();
}
举报

相关推荐

0 条评论