Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. UCHAR to QString

UCHAR to QString

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 2.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Cobra91151C Offline
    Cobra91151C Offline
    Cobra91151
    wrote on last edited by Cobra91151
    #1

    Hi! I want to display Wireless AP names in QTreeWidget as QTreeWidgetItems. The problem is when I use QString::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 to QString 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?

    1 Reply Last reply
    0
    • Paul ColbyP Offline
      Paul ColbyP Offline
      Paul Colby
      wrote on last edited by
      #2

      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.

      Cobra91151C 1 Reply Last reply
      3
      • Paul ColbyP Paul Colby

        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.

        Cobra91151C Offline
        Cobra91151C Offline
        Cobra91151
        wrote on last edited by
        #3

        @Paul-Colby

        Now it's properly displays the AP. Thank you.

        1 Reply Last reply
        1

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved