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. Checking is a drive is readable in Qt pops up a "no disk" error in Windows 7
Forum Updated to NodeBB v4.3 + New Features

Checking is a drive is readable in Qt pops up a "no disk" error in Windows 7

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 828 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.
  • H Offline
    H Offline
    Hawkeye64
    wrote on last edited by
    #1

    Here is a snippet of code:

    @
    QStringList getAvailableDrives()
    {
    QStringList drives;
    QFileInfoList fiList = QDir::drives();
    bool firstRemovableDone = false;

    QString path;
    foreach( const QFileInfo& fi, fiList )
    {
      path = fi.absoluteFilePath();
    
      if ( !fi.exists() )
      {
        continue;
      }
    
      if ( !QFile::exists( path ) )
      {
        continue;
      }
    
      if ( !fi.isReadable() )
      {
        continue;
      }
      // ...
    

    @

    The issue is I am in a corporate setting with network drives, mapped drives, whatever. The QDir::drives() is returning all my normal drives, but is also returning "R:/", "S:/", "T:/" and "X:/". I can't access these drives and have no idea where they are coming from. But, fi.exists(), QFile::exists() both say they agree. Then it falls down to fi.isReadable(). In the past (4.7, 4.8) this returned false. But, 5.1.1 is doing something different and Windows 7 is popping up a dialog that requires User input. I don't want this if I am checking if the drive is readable.

    The dialog is like this:

    There is no disk in the drive. Please insert a disk into drive \Device\Harddisk3\DR8.
    [Cancel] [Try Again] [Continue]

    This comes from line 791 of qfilesystemengine_win.cpp in the ::_waccess call:

    @ // calculate user permissions
    if (what & QFileSystemMetaData::UserReadPermission) {
    if (::_waccess((wchar_t*)entry.nativeFilePath().utf16(), R_OK) == 0)
    data.entryFlags |= QFileSystemMetaData::UserReadPermission;
    data.knownFlagsMask |= QFileSystemMetaData::UserReadPermission;
    }
    @

    So far, I have been able to work-around this by calling the following code before the fi.isReadable():
    @
    bool isValidDrive( const QString& path )
    {
    bool valid = true; // default

    #ifdef Q_OS_WIN
    LPCWSTR szHD = (LPCWSTR)path.utf16();
    UCHAR szFileSys[255], szVolNameBuff[255];
    DWORD dwSerial, dwMFL, dwSysFlags;
    BOOL bSuccess;

    bSuccess = ::GetVolumeInformationW(
      szHD,
      (LPWSTR)szVolNameBuff,
      255,
      &dwSerial,
      &dwMFL,
      &dwSysFlags,
      (LPWSTR)szFileSys,
      255
      );
    
    valid = bSuccess;
    
    if ( !bSuccess )
    {
      qDebug() << "Error number " << ::GetLastError();
      return false;
    }
    

    #endif // Q_OS_WIN

    return valid;
    

    }
    @

    But I am looking for a more OS independent way of checking. Suggestions?

    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