SSID 删除重复问题

SSID remove duplicates issue

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

截图:

我已经尝试通过 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);
}

实际代码非常庞大和复杂,包含结构、向量和向量迭代插入 QTreeWidgetItemsQTreeWidget

我已经检查过了,它删除了最后两个 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 一样,否则它将是空的。

截图:

所以代码:

           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 profile, no profile, connected) 标志。我还创建了一些具有以下值的常量:

3 - connected, 2 - has profile, 0 - no profile

当我用这些常量值检查网络时,我得到的例子只有 no profilehas profileconnected。但是我需要一些检查来显示 has profile,并且只有 no profile 才显示新的。有任何想法吗?谢谢。

更新:4: 我重新设计了应用程序以支持这样的 APs(带有配置文件)。问题已解决。

由于 QTreeWidget 不检查是否插入了重复项,因此您需要使用支持排除重复项的额外容器,例如 QMapQHash.

在您的树形小部件中插入项目之前,请检查您的 map/hash table 中是否已经存在 SSID(作为密钥)。如果检查说有这样的SSID,就不要插入了。