qt qhash

'http://memotiyou.blogspot.com/2012/01/qt-c-qhash_6954.html'
ainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    QHash<int, QString> hash;//keyはint, valueはQString
    hash[0] = "Zero!";
    hash[1] = "One!";
    hash.insert(2, "Two!");

    ui->label->setText(hash[2]+ hash.value(1) + hash.value(0));
}
QHash<QString, QString> hash;

hash["key1"] = "Zero!";
QString temp;
QHash<int, QString>::const_iterator i = hash.constBegin();
while (i != hash.constEnd()) {
    temp += tr("%1 : %2  ").arg(i.key()).arg(i.value());
    ++i;
}
posted @ 2022-05-09 14:09  mtgold  阅读(73)  评论(0编辑  收藏  举报