https://developer.gnome.org/gio/stable/GVolumeMonitor.html#g-volume-monitor-get-mount-for-uuid
.pro文件
QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = mountdevice TEMPLATE = app PKGCONFIG +=gio-2.0 LIBS +=-lgio-2.0 -lglib-2.0 CONFIG += c++11 link_pkgconfig SOURCES += main.cpp\ mainwindow.cpp HEADERS += mainwindow.h
GVolumeMonitor* monitor = g_volume_monitor_get(); GList* mountDeviceList = g_volume_monitor_get_mounts(monitor); GList* it = NULL; for(it = mountDeviceList; it; it = it->next) { qDebug() << "mount device list:" << it->data; } GList* mountVolumeList = g_volume_monitor_get_volumes(monitor); for(it = mountVolumeList; it; it = it->next) { qDebug() << "mount volume list:" << it->data; }
GVolumeMonitor是用来列举用户感兴趣的计算机上面的设备和卷。换句话说,就是一个文件选择器或者文件管理器在侧边栏会显示的列表。
GVolumeMonitor不是 thread-default-context aware(?不理解), 因此不能在除了主线程中的其他地方使用,因为他没有thread-default-context.