qt容器类的使用

 添加头文件

#include
#include
#include
#include
#include
#include
#include

相应容器类的关键用法代码

 //队列
    QQueue myqueue;
    myqueue.enqueue(10);
    myqueue.enqueue(20);
    myqueue.enqueue(60);
    while (!myqueue.isEmpty()) {
        qDebug() << myqueue.dequeue() < queue;
    queue.enqueue("hello");
    queue.enqueue("world");
    queue.enqueue("qt code");
    while (!queue.isEmpty()) {
        qDebug() <<"QQueue: "<< queue.dequeue().data() < mystack;
    mystack.push(10);
    mystack.push(20);
    mystack.push(30);
    while (!mystack.isEmpty()) {
        qDebug()<<"QStack: "<< mystack.pop() < myvector;
    myvector.append(50);
    myvector.append(30);
    myvector.append(20);
    myvector.push_front(100);
    QVector::iterator iter;
    for (iter=myvector.begin();iter != myvector.end();iter++) {
        qDebug() <<"QVector: "<< *iter << endl;
    }

    QList mylist;
    mylist.append("hello ");
    mylist.append("world ");
    mylist.push_front("list : ");
    QList::iterator list_iter;
    for (list_iter=mylist.begin();list_iter != mylist.end();list_iter++) {
        qDebug()<<"QList: "<< list_iter->data() <data() < myhash;
    myhash.insert("alen",1);
    myhash["lucy"]=2;
    myhash["peter"]=3;
    QHashIterator hash_iter(myhash);
    while (hash_iter.hasNext()) {
        hash_iter.next();
        qDebug() << hash_iter.key() << ":" << hash_iter.value();
    }

//map
    QMap map;
    map.insert("key 2", 2);
    map.insert("key 0", 0);
    map.insert("key 1", 1);
    map["key 3"]=3;

    // 通过QList获取键值对
    QList kList = map.keys();
    for(int i=0; i vList = map.values();
    for(int i=0; i it(map);
        while(it.hasNext())
        {
            it.next();
            qDebug() << it.key() << ":" << it.value();
        }

 

你可能感兴趣的:(QT)