PDA

View Full Version : Hot plug and button event



kpmsivachand
26th January 2009, 14:54
Hello guys!

I need to refresh the my form whenever the usb device inserted or removed.... I have little knowledge about the hotplug. I dont know how to connect the hotplug event to my button event. Simply i can say,i want to invoke the button event when ever hotplug script run.... Can anybody help???


Advance thanks...

QbelcorT
26th January 2009, 15:43
Hi,
Actually I am going through the same thing right now. I am using QtEmbedded 4.4.1 with Linux and I cannot find any solution for doing this. It seems QtExtended has a QBaseModule made for these kind of things.
I did it kind of awkwardly but it works. It my hotplug mounting script when the usb device gets mounted I create a file in /var/run/usb/ with the usb type info. Then in my remove script I delete that file. In my Qt Application I have a thread in my usb window that checks if that file exists QFile.exists(). I then signal my window if connected or not. If you find an easier method let me know.
Thanks.

QbelcorT
27th January 2009, 05:43
Hi,
I think D-Bus is another blackhole I don't have time for right now, I'll consider this on my next version. (recompile qt, libraries, etc).
Here is the response I received from Qt Tech support:
For Qt Embedded or Qt/Linux:
- If you want to know when a USB stick has been plugged in and then read data from it, this should be relatively easy. When the USB stick is plugged, most morden Linux kernels will automatically mount it to a particular location that would let you access it using the normal file system operation. If the Linux kernel is compiled with HAL support (Hardware Abstraction Layer) and D-Bus is installed then you can use the 'hald' daemon to receive notifications. When any device is plugged in, you can use the QtDBus? module to listen on the system bus and be notifed of new devices:


if (!QDBusConnection::systemBus().isConnected()) {
qDebug() << "Cannot connect to system bus";
}

bool connected = QDBusConnection::systemBus().connect(
"org.freedesktop.Hal",
"/org/freedesktop/Hal/Manager",
"org.freedesktop.Hal.Manager",
"DeviceAdded",
this, SLOT(deviceAdded()));

kpmsivachand
27th January 2009, 15:41
Thanks QbelcorT!

thanks for the code let me try out now...... :)

binaural
9th July 2009, 10:06
Hi,

I try to use this code snippet for test if usb device is connected but I get error during Dbus connection : connect: Resource temporarily unavailable.

I'm using opensuse 11.

Thanks

binaural
9th July 2009, 16:15
Sorry my fault everything works fine now.

sreeram
16th July 2013, 07:49
Hi QbelcorT & kpmsivachand,

I am also working on same thing hotplug to the qt application.How can I confirm my Ubuntu-11.10(Kernel-3.0) compiled with HAL.

I have posted my Qt application hot plug problem in one of the Qt fourm. Can you please read following link to understand my question .

http://www.qtcentre.org/threads/55412-Notification-to-the-Qt-application-while-USB-plug-unplug?p=247675#post247675