#include <solid/devicenotifier.h>
#include <solid/device.h>
#include <QApplication.h>
#include <QDebug.h>
class App : public QApplication
{
Q_OBJECT
public :
App( int args, char **argv);
virtual ~App();
private slots:
void deviceAdded( const QString &udi);
void deviceRemoved( const QString &udi);
};
* This source code was highlighted with Source Code Highlighter .
#include "app.h"
App::App( int args, char **argv )
: QApplication(args, argv)
{
//
qDebug() << "===== All available devices =====" ;
foreach ( const Solid::Device &device, Solid::Device::allDevices())
{
qDebug() << device.udi().toLatin1().constData();
}
//
qDebug() << "\n===== Start monitoring for new =====" ;
Solid::DeviceNotifier *notifier = Solid::DeviceNotifier::instance ();
connect(notifier, SIGNAL(deviceAdded ( const QString &)), this , SLOT(deviceAdded(QString const &)));
connect(notifier, SIGNAL(deviceRemoved(QString const &)), this , SLOT(deviceRemoved(QString const &)));
}
void App::deviceAdded(QString const &udi)
{
qDebug() << "Added" << udi.toLatin1().constData();
}
void App::deviceRemoved(QString const &udi)
{
qDebug() << "Removed" << udi.toLatin1().constData();
}
App::~App()
{
//TODO
}
* This source code was highlighted with Source Code Highlighter .
#include "app.h"
int main( int args, char **argv)
{
App app( args, argv );
return app.exec();
}
* This source code was highlighted with Source Code Highlighter .
project(solid)
find_package(KDE4 REQUIRED)
include_directories( ${KDE4_INCLUDES} )
set (mySources main.cpp app.h app.cpp)
kde4_add_executable(solid ${mySources})
target_link_libraries(solid ${KDE4_KDEUI_LIBS} ${KDE4_KPARTS_LIBS} )
install(TARGETS solid DESTINATION bin)
* This source code was highlighted with Source Code Highlighter .
cmake .
make
./solid
* This source code was highlighted with Source Code Highlighter .
Added /org/freedesktop/Hal/devices/usb_device_58f_6387_51ZT24OY_4
Added /org/freedesktop/Hal/devices/usb_device_58f_6387_51ZT24OY_4_if0
Added /org/freedesktop/Hal/devices/usb_device_58f_6387_51ZT24OY_4_usbraw
Added /org/freedesktop/Hal/devices/usb_device_58f_6387_51ZT24OY_4_if0_scsi_host
Added /org/freedesktop/Hal/devices/usb_device_58f_6387_51ZT24OY_4_if0_scsi_host_scsi_device_lun0
Added /org/freedesktop/Hal/devices/usb_device_58f_6387_51ZT24OY_4_if0_scsi_host_scsi_device_lun0_scsi_generic
Added /org/freedesktop/Hal/devices/storage_serial_JetFlash_TS2GJFV60_51ZT24OY_0_0
Added /org/freedesktop/Hal/devices/volume_uuid_4979_CC88
* This source code was highlighted with Source Code Highlighter .
Removed /org/freedesktop/Hal/devices/usb_device_58f_6387_51ZT24OY_4_if0_scsi_host_scsi_device_lun0_scsi_generic
Removed /org/freedesktop/Hal/devices/volume_uuid_4979_CC88
Removed /org/freedesktop/Hal/devices/storage_serial_JetFlash_TS2GJFV60_51ZT24OY_0_0
Removed /org/freedesktop/Hal/devices/usb_device_58f_6387_51ZT24OY_4_if0_scsi_host_scsi_device_lun0
Removed /org/freedesktop/Hal/devices/usb_device_58f_6387_51ZT24OY_4_if0_scsi_host
Removed /org/freedesktop/Hal/devices/usb_device_58f_6387_51ZT24OY_4_if0
Removed /org/freedesktop/Hal/devices/usb_device_58f_6387_51ZT24OY_4_usbraw
* This source code was highlighted with Source Code Highlighter .
Source: https://habr.com/ru/post/54616/
All Articles