1

is it possible wit Qt Qprocess to detect if a mounted Loacation(maybe NAS) is connected? Generally i would check in /proc/mounts if there is an entry, but if i disconnect to the NAS the file doesn't realizes it. with the df command i can check if a mountpoint is available. But if the connection is disconnected the df process doesn't gives an output. Maybe infinite.

I tried it with

QProcess p;
p.start("bash", QStringList() << "-c" <<
      "df -P -T /media/storage/ | grep QIS | awk -F ' ' '{print $1}'");
if (p.waitForFinished(2))
{
  qDebug() << "Nothing";
  p.close();
}

But nothing happens.

It seems that my program "freezes" when i try to df to a directory which ist'n mounted. Is it possible to cancel the process if there is no answer from the df process after, for example, 2 seconds?

scopchanov
  • 7,966
  • 10
  • 40
  • 68
DaveR
  • 63
  • 1
  • 10
  • 1
    Are you looking for https://doc.qt.io/qt-5/qstorageinfo.html? – scopchanov Nov 09 '21 at 09:54
  • Does this answer your question? [Detecting mounted drives on Linux and Mac OS X](https://stackoverflow.com/questions/18600377/detecting-mounted-drives-on-linux-and-mac-os-x) – Ulrich Eckhardt Nov 09 '21 at 10:00

1 Answers1

1

Regarding QProcess, QProcess::waitForFinished takes msec as argument, not sec. Furthermore, it is better to connect to QProcess::finished signal instead of blocking the event loop.

That being said, why using QProcess, when there is a QStorageInfo with a mountedVolumes method:

for (const auto &storage : QStorageInfo::mountedVolumes()) {
    if (storage.isValid() && storage.isReady()) {
        if (!storage.isReadOnly()) {
            // ...
        }
    }
}
scopchanov
  • 7,966
  • 10
  • 40
  • 68
  • Thank but this doesn't work for me. With QStorageInfo i can print all mounted devices but there is still no answer wehen i try to list my unmounted device. – DaveR Nov 09 '21 at 14:48
  • @DaveR, how do you expect to see something, which does not exist? – scopchanov Nov 09 '21 at 15:18