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] How to check whether inserted SD Card is write protected or not in Qt?

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

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 2.1k Views
  • 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

    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
    0
    • S Offline
      S Offline
      Stoned Jesus
      wrote on last edited by
      #2

      I have updated the question. Please check :)

      --
      Thanks & Regards,
      Stoned Jesus

      1 Reply Last reply
      0
      • sierdzioS Offline
        sierdzioS Offline
        sierdzio
        Moderators
        wrote on last edited by
        #3

        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
        0
        • S Offline
          S Offline
          Stoned Jesus
          wrote on last edited by
          #4

          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
          0

          • Login

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