SSID删除重复问题

时间:2017-11-12 17:25:46

标签: c++ qt windows-applications wlan

我想从wlan SSID删除QTreeWidget个重复项,或者在QTreeWidget中显示之前添加一些重复项检查。

截图:

enter image description here

我已尝试按QSet删除重复项,但它也会删除应列在列表中的SSID,因此在我的情况下它不起作用。

示例代码:

  QStringList apList;

  for (int i = 0; i < (int)pBssList->dwNumberOfItems; i++) {
       pBssEntry = (WLAN_AVAILABLE_NETWORK *)&pBssList->Network[i];
       apList << QString::fromUtf8(reinterpret_cast<char *>(pBssEntry->dot11Ssid.ucSSID), pBssEntry->dot11Ssid.uSSIDLength);
  }

  QSet<QString> apSet = QSet<QString>::fromList(apList);

for (int j = 0; j < apSet.count(); j++) {
    pBssEntry = (WLAN_AVAILABLE_NETWORK *)&pBssList->Network[j];
    qDebug() << QString::fromUtf8(reinterpret_cast<char *>(pBssEntry->dot11Ssid.ucSSID), pBssEntry->dot11Ssid.uSSIDLength);
}

实际代码非常庞大且复杂,包含QTreeWidgetItems的结构,向量和向量迭代QTreeWidget

我已经检查了它,并将最后两个SSID删除为重复项。

我想要与Windows中的行为相同。有任何想法吗?感谢。

更新

 QMap<QString, int> apMap;

 for (int i = 0; i < (int)pBssList->dwNumberOfItems; i++) {
      pBssEntry = (WLAN_AVAILABLE_NETWORK *)&pBssList->Network[i];
      apMap.insert(QString::fromUtf8(reinterpret_cast<char *>(pBssEntry->dot11Ssid.ucSSID), pBssEntry->dot11Ssid.uSSIDLength), i);
    }

    qDebug() << apMap.count();
    qDebug() << apMap.uniqueKeys();
    QMap<QString, int>::iterator it;

    for (it = apMap.begin(); it != apMap.end(); it++) {
        qDebug() << it.key();
    }

现在它正在运行,但我还需要修复其他功能。

更新:2 最后,我修复了错误并将所有数据添加到QTreeWidget,但有时候配置文件列与SSID列不同。问题是没有添加配置文件,而是显示SSID,而不是在配置文件列中的Windows OS中,否则它将为空。

截图:

enter image description here

所以代码:

           for (int j = 0; j < apHash.uniqueKeys().count(); j++) {
                pBssEntry = (WLAN_AVAILABLE_NETWORK *)&pBssList->Network[j];
                if (wcslen(pBssEntry->strProfileName) != NULL) {
                    wirelessAPData.profile = QString::fromWCharArray(pBssEntry->strProfileName);
                    wirelessAPData.name = apHash.uniqueKeys().value(j);
                } else {
                    if (!apHash.uniqueKeys().value(j).isEmpty()) {
                        wirelessAPData.profile = apHash.uniqueKeys().value(j);
                        wirelessAPData.name = apHash.uniqueKeys().value(j);
                    } else {
                        wirelessAPData.profile = QObject::tr("Hidden network");
                        wirelessAPData.name = QObject::tr("Hidden network");
                    }
                }
           }

此外,我已将QMap更改为QHash以使其更快,wirelessAPData只是struct。感谢。

更新:3 我认为应该有更好的解决方案,因为这些SSID不是重复的,它们有不同的Flags,例如其中一些有(has profileno profile,{ {1}})标志。我还创建了一些带有值的常量:

connected3 - connected2 - has profile

当我使用这些常量值检查网络时,我仅使用0 - no profileno profilehas profile获取。但我需要使用connected显示一些支票,而has profile只显示新支票。有任何想法吗?感谢。

更新:4: 我重新设计了应用程序以支持此类no profile(带有配置文件)。问题已得到解决。

1 个答案:

答案 0 :(得分:0)

由于QTreeWidget不会检查是否插入了重复项,因此您需要使用其他容器来支持排除重复项,例如QMapQHash

在树窗口小部件中插入项目之前,请检查地图/哈希表中是否已存在(作为关键字)SSID。如果检查告知有这样的SSID,则不要插入它。