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. [SOLVED] cannot convert from 'QString' to 'LPCWSTR' ???
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] cannot convert from 'QString' to 'LPCWSTR' ???

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 11.9k 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.
  • S Offline
    S Offline
    Stoned Jesus
    wrote on last edited by
    #1

    I am working on an app where I need to display the file system format of the SD card. Since I couldnt find any Qt API's for it, I choose a windows API GetVolumeInformation and did it as follows:

    @TCHAR volumeName[MAX_PATH + 1] = { 0 };
    TCHAR fileSystemName[MAX_PATH + 1] = { 0 };
    DWORD serialNumber = 0;
    DWORD maxComponentLen = 0;
    DWORD fileSystemFlags = 0;

    LPCWSTR path = deviceData->m_strPath;

    if (GetVolumeInformation(
    path,
    volumeName,
    ARRAYSIZE(volumeName),
    &serialNumber,
    &maxComponentLen,
    &fileSystemFlags,
    fileSystemName,
    ARRAYSIZE(fileSystemName)))
    {
    qDebug()<<fileSystemName[0];
    qDebug()<<fileSystemName[1];
    qDebug()<<fileSystemName[2];
    qDebug()<<fileSystemName[3];
    qDebug()<<fileSystemName[4];
    }@

    path indicates the SD card path and when I run the app, it throws the following error:
    "cannot convert from 'QString' to 'LPCWSTR'". Where am i making a mistake??? Please help!!

    --
    Thanks & Regards,
    Stoned Jesus

    1 Reply Last reply
    0
    • C Offline
      C Offline
      cincirin
      wrote on last edited by
      #2

      See "QString::fromWCharArray":http://qt-project.org/doc/qt-5.0/qtcore/qstring.html#fromWCharArray

      @
      qDebug()<<QString::fromWCharArray(fileSystemName[0]);
      ...
      @

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Stoned Jesus
        wrote on last edited by
        #3

        Nevermind I got the solution.

        LPCWSTR path = deviceData->m_strPath.utf16();

        --
        Thanks & Regards,
        Stoned Jesus

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          I suppose the error is on line 7, you have to convert the QString to an LPCWSTR, IIRC using "toWCharArray":http://qt-project.org/doc/qt-4.8/qstring.html#toWCharArray should do the trick

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • S Offline
            S Offline
            Stoned Jesus
            wrote on last edited by
            #5

            Thank you SGaist :)

            [quote author="SGaist" date="1363091161"]Hi,

            I suppose the error is on line 7, you have to convert the QString to an LPCWSTR, IIRC using "toWCharArray":http://qt-project.org/doc/qt-4.8/qstring.html#toWCharArray should do the trick[/quote]

            --
            Thanks & Regards,
            Stoned Jesus

            1 Reply Last reply
            0
            • S Offline
              S Offline
              Stoned Jesus
              wrote on last edited by
              #6

              My output now displays 70 65 84 51 50. If anyone wants it in a string format use as follows:

              QString::fromUtf16(fileSystemName);

              --
              Thanks & Regards,
              Stoned Jesus

              1 Reply Last reply
              0

              • Login

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