Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    [SOLVED] How to check whether inserted SD Card is write protected or not in Qt?

    General and Desktop
    2
    4
    1910
    Loading More Posts
    • 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
      Stoned Jesus last edited by

      Hi friends I am working on an application where I should check the file system of the SD card and also I need to check whether the SD card inserted is write protected or not. I was successful in getting the file system details 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.utf16(); // deviceData gives me the path of the SD Card
      
      // Get the file system details
      if (GetVolumeInformation(
                               path,
                               volumeName,
                               ARRAYSIZE(volumeName),
                               &serialNumber,
                               &maxComponentLen,
                               &fileSystemFlags,
                               fileSystemName,
                               ARRAYSIZE(fileSystemName)))
                  {
                      newData.strFileSystem = QString::fromUtf16(fileSystemName);                
                  }
      
       m_SDInfoList.append(newData); // m_SDInfoList is QList@
      

      With this approach I get to know whether the file system is FAT32 or NTFS. Now I want to achieve the write protected details. Is their a Qt API that can gimme whether the inserted SD Card is write protected or not??? Please help :)

      Update:

      This is what I did using QFileInfo:

      @QFileInfo fileInfo(deviceData->m_strPath);

      if(!fileInfo.isWritable())
      {
      newData.strStatus = "WriteProtect Enabled";
      }
      else
      {
      newData.strStatus = "WriteProtect Disabled";
      }@

      It always ends up giving me WriteProtect Disable even though I have set the write protected permission. Am I missing something??

      --
      Thanks & Regards,
      Stoned Jesus

      1 Reply Last reply Reply Quote 0
      • S
        Stoned Jesus last edited by

        I have updated the question. Please check :)

        --
        Thanks & Regards,
        Stoned Jesus

        1 Reply Last reply Reply Quote 0
        • sierdzio
          sierdzio Moderators last edited by

          There are classes in QtSensors and in some external projects (QDriveInfo?) that would help you here. I think it returns false for ::isWritable() because you do not point to a valid file path (it's the path to the device, but not a potential file).

          (Z(:^

          1 Reply Last reply Reply Quote 0
          • S
            Stoned Jesus last edited by

            Thanks sierdzio :)

            [quote author="sierdzio" date="1366697003"]There are classes in QtSensors and in some external projects (QDriveInfo?) that would help you here. I think it returns false for ::isWritable() because you do not point to a valid file path (it's the path to the device, but not a potential file).[/quote]

            --
            Thanks & Regards,
            Stoned Jesus

            1 Reply Last reply Reply Quote 0
            • First post
              Last post