Solved UCHAR to QString
-
Hi! I want to display Wireless AP names in
QTreeWidget
asQTreeWidgetItems
. The problem is when I useQString::fromWCharArray(pBssEntry->dot11Ssid.ucSSID)
function, it displays as blank items.Code:
QTreeWidgetItem apItem = new QTreeWidgetItem(wirelessData); //wirelessData is QTreeWidget apItem->setText(0, QString::fromWCharArray(pBssEntry->dot11Ssid.ucSSID));
How to convert
UCHAR
toQString
or what other solutions? Thanks in advance.Update:
I have changed code to:apItem->setText(0, QString((uchar)*pBssEntry->dot11Ssid.ucSSID))
Now it displays only one letter from AP name. How to output full AP name?
-
Hi @Cobra91151,
Have a look at qnativewifiengine.cpp line 152 for an example... it looks like:
QString networkName; ... networkName = QByteArray(reinterpret_cast<char *>(network.dot11Ssid.ucSSID), network.dot11Ssid.uSSIDLength);
This is, presumably, using the QString &QString::operator=(const QByteArray &ba) operator, which:
Assigns ba to this string. The byte array is converted to Unicode using the fromUtf8() function. ...
So, unless you care about the
network.strProfileName
check (see the qtbase code linked above for context), then you can probably just do something like:apItem->setText(0, QString::fromUtf8(reinterpret_cast<char *>(pBssEntry->dot11Ssid.ucSSID), pBssEntry->dot11Ssid.uSSIDLength));
Cheers.
-
Now it's properly displays the AP. Thank you.