Qt -------- 容器类

QVector(数组)、QLinkedList(链表)、QMap(映射表)、QHash(哈希表)、QQueue(队列)

QHash遍历举例:

法1:

QThread& ThreadHandle::getThread()
{
    auto it = hash_threadSize.begin();
    auto ite = hash_threadSize.begin();
    for(++it; it != hash_threadSize.end(); ++it)
    {
        if(ite.value() > it.value())
        {
            ite = it;
        }
    }
    ite.value()++;
    return *ite.key();
}

 法2:

Server::~Server()
{
    QHash<QThread *, qintptr>::const_iterator i;
    for(i=hash_threadSocketDescriptor.constBegin(); i!=hash_threadSocketDescriptor.constEnd(); i++)
    {
        i.key()->exit(0);
        i.key()->wait();
    }
    qDebug() << "关闭所有服务器产生的线程";
}

 法3:

QList<QNetworkInterface> interfaceList = QNetworkInterface::allInterfaces();
foreach (QNetworkInterface interface, interfaceList)
{
//        qDebug() << interface.humanReadableName(); //打印网卡名称
    QList<QNetworkAddressEntry> entryList = interface.addressEntries();
    foreach(QNetworkAddressEntry entry, entryList)
    {
        QString str = entry.broadcast().toString();
        if(str != "")
        {
//                qDebug() << str; //打印可用的广播地址
            writeDatagram(data, data.size(), QHostAddress(str), 12345);
        }
    }
}
原文地址:https://www.cnblogs.com/god-of-death/p/7593295.html