Get disk type in QT
For linux, you can tell whether the kernel has detected a SSD disk by reading special file
/sys/block/<disk>/queue/rotational
For instance, cat /sys/block/sda/queue/rotational
writes 1
if sda disk is HDD and 0
if it's SSD.
For Windows, you can open a drive by opening special file \\.\PhysicalDrive<number>
, for instance \\.\PhysicalDrive0
. It can the be used with DeviceIOControl
to query properties, using IOCTL_STORAGE_QUERY_PROPERTY
IO control. It seems StorageDeviceSeekPenaltyProperty
may be what you're after, as HDD have a seek penalty while SSD don't. Alas I don't have a windows environment around to test right now.
For portability, I highly doubt such system-dependent information is available in a portable way. You'll have to use #ifdef
/#else
/#endif
macros to select an implementation depending on current target.
How to get the hard disk partition information QT
I find a solution that I think is more helpful Displaying Volume Paths
thank you all any way.
How to determine how much free space on a drive in Qt?
I know It's quite old topic but somebody can still find it useful.
Since QT 5.4 the QSystemStorageInfo
is discontinued, instead there is a new class QStorageInfo
that makes the whole task really simple and it's cross-platform.
QStorageInfo storage = QStorageInfo::root();
qDebug() << storage.rootPath();
if (storage.isReadOnly())
qDebug() << "isReadOnly:" << storage.isReadOnly();
qDebug() << "name:" << storage.name();
qDebug() << "fileSystemType:" << storage.fileSystemType();
qDebug() << "size:" << storage.bytesTotal()/1024/1024 << "MB";
qDebug() << "availableSize:" << storage.bytesAvailable()/1024/1024 << "MB";
Code has been copied from the example in QT 5.5 docs
C++ Qt - Get Physical Disk Size (Win32)
I think this issue is mainly cosmetic as a result of inconsistencies in measurements used by Operating Systems and Hard Drive manufacturers. Check this wikipedia page for more information. Perhaps find a way to do the math while treating 1 Kilobyte as 1000 bytes (instead of 1024), 1 Megabyte as 1000 * 1000 and so on -- instead of 1 kilobyte as 1024 bytes etc.
[Qt][Linux] List drive or partitions
You can use /etc/mtab
file to obtain a mountpoints list.
QFile file("/etc/mtab");
if (file.open(QFile::ReadOnly)) {
QStringList mountpoints;
while(true) {
QStringList parts = QString::fromLocal8Bit(file.readLine()).trimmed().split(" ");
if (parts.count() > 1) {
mountpoints << parts[1];
} else {
break;
}
}
qDebug() << mountpoints;
}
Output on my machine:
("/", "/proc", "/sys", "/sys/fs/cgroup", "/sys/fs/fuse/connections", "/sys/kernel/debug", "/sys/kernel/security", "/dev", "/dev/pts", "/run", "/run/lock", "/run/shm", "/run/user", "/media/sf_C_DRIVE", "/media/sf_C_DRIVE", "/media/sf_D_DRIVE", "/run/user/ri/gvfs")
Note that QFile::atEnd()
always returns true for this file, so I didn't use it in my code.
QDir::Drives
is 4 according to the documentation. It's static integer value of enum item, it doesn't show anything and you shouldn't care about it in most cases. QDir::drives()
contains exactly one item (for root filesystems) when executed on Linux.
How can I determine the type of a particular drive?
I'm not sure what you didn't understand about the documentation you linked to...
The sole argument accepted by the function is the root directory of the drive you want to get information about (including a trailing backslash). The function returns a value indicating which type of drive that is. A chart is shown that gives the possible return values and what each of them mean.
For example:
GetDriveType(_T("C:\\")) // returns DRIVE_FIXED if C:\ is my hard drive
GetDriveType(_T("A:\\")) // returns DRIVE_REMOVABLE if A:\ is my floppy drive
GetDriveType(_T("D:\\")) // returns DRIVE_CDROM if D:\ is a CD-ROM drive
GetDriveType(_T("N:\\")) // returns DRIVE_REMOTE if N:\ is a network drive
It also says that if you want to determine whether a drive is a USB-type drive, you need to call the SetupDiGetDeviceRegistryProperty
function and specify the SPDRP_REMOVAL_POLICY
property.
How to check that QImage::save() has finished writing to disk?
Your diagnosis of the issue is incorrect. Once image.save
has returned, the filesystem is in a consistent state and you can forcibly exit the application at that very point: the file will have correct contents. Whether the on-disk state is consistent is unknown, but all that means is that you shouldn't reset nor forcibly power-off the machine. Your application is free to quit, though.
Your issue is something else. Who knows what: you failed to provide a test case.
It's not necessary to deal with worker threads and objects manually. Leverage QtConcurrent
. It's supposed to be easy, and it is. Namely:
class MyWindow : public QWidget {
Q_OBJECT
CountDownLatch m_latch;
Q_SIGNAL void imageSaved(const QString & filename);
Q_SIGNAL void imageSaveFailed(const QString & filename);
void saveImage(const QImage & image, const QString & filename) {
auto lock = m_latch.lock();
QtConcurrent::run([=]{ // captures this, lock, image and filename
if (image.save(filename, "PNG", 100))
emit imageSaved(filename);
else
emit imageSaveFailed(filename);
});
}
...
// MyWindow's destructor will block until all image savers are done
};
For implementation(s) of CountDownLatch
, see this question.
Get current CPU, RAM and Disk drive usage using Qt
You need to use platform specific code to detect resource usage.
For fastest file access to calculate hashes, use memory mapped files (QMemoryFile)
Related Topics
Undocumented Switches for 'Date' Command
Time Taken by 'Less' Command to Show Output
Qemu Simple Backend Tracing Dosen'T Print Anything
Where Do Char Device Appear After Cdev_Add() Registers Successfully with Major on 117.
Shell Bash Script to Print Numbers in Ascending Order
Sigbus While Doing Memcpy from Mmap Ed Buffer Which Is in Ram as Identified by Mincore
How to Find Size of Heap Present in Linux
Debian 7, Fstab, Mount.Cifs Invalid Argument
Mount -T Cifs Works on One Version of Linux But Not Another
Cannot Get Qwindow::Fromwinid to Work Properly
In Linux, Do There Exist Functions Similar to _Clearfp() and _Statusfp()
Host Doing Unnecessary Dns Lookup for Localhost
Whats The Easiest Way to Send Messages to My Linux Daemon App
Using Command Substitution Inside a Sed Script, with Arguments
Linux Nasm Move a Value in Al Up to Ax
Moving a Git Repo to Another Server
Visual Studio - X11: The Display Environment Variable Is Missing