#include <QStringList>#include <QCoreApplication>#include <QFileSystemWatcher>#include <QtDebug>class Watcher : public QFileSystemWatcher { Q_OBJECTpublic: Watcher() { connect(this, SIGNAL(fileChanged(const QString &)), SLOT(show(const QString &))); }private slots: void show(const QString & path) { qDebug() << path; }};int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); Watcher w; w.addPath("/proc/bus/usb/device"); return a.exec();}#include "moc_main.cpp"
C++ (Qt)DeviceManager::DeviceManager( QObject *parent ) : QObject( parent ), m_deviceScaner( new DeviceScaner( this ) ){ // Подключаемся к сервисам Hal if( !QDBusConnection::systemBus().connect( "org.freedesktop.Hal", "/org/freedesktop/Hal/Manager", "org.freedesktop.Hal.Manager", "DeviceAdded", this, SLOT( halDeviceAdded( const QString & ) ) ) ) qWarning() << "Error connection signal DeviceAdded"; if( !QDBusConnection::systemBus().connect( "org.freedesktop.Hal", "/org/freedesktop/Hal/Manager", "org.freedesktop.Hal.Manager", "DeviceRemoved", this, SLOT( halDeviceRemoved( const QString & ) ) ) ) qWarning() << "Error connection signal DeviceRemoved";} void DeviceManager::halDeviceAdded( const QString &udi ){ qWarning() << "Added : " << udi;} void DeviceManager::halDeviceRemoved( const QString &udi ){ qWarning() << "Removed : " << udi;}
C++ (Qt)int main( int argc, char *argv[] ){ Q_INIT_RESOURCE( demon ); QApplication app( argc, argv ); if( !QDBusConnection::systemBus().isConnected() ) { qWarning() << "Cannot connect to the D-BUS session bus."; return 1; } MainWindow *mw = new MainWindow; mw->show(); return app.exec();}
C++ (Qt) QDBusInterface iDev( "org.freedesktop.Hal", udi, "org.freedesktop.Hal.Device", QDBusConnection::systemBus() ); if( !iDev.isValid() ) return QString(); QDBusReply<QString> category = iDev.call( "GetPropertyString", "info.category" );
C++ (Qt) QDBusReply<QString> category = iDev.call( "GetPropertyString", "info.category" );