Hi Thiago, Thanks for the earlier post.
Did manage to work better with USB sample code using QtDBus. However, as I got to list the device mounted paths now, could you please let me know how to make calls to fetch the device mounted paths. Thanks and Regards, Ramakanth -----Original Message----- From: interest-bounces+ramakanthreddy_kesireddy=mahindrasatyam....@qt-project.org [mailto:interest-bounces+ramakanthreddy_kesireddy=mahindrasatyam....@qt-project.org] On Behalf Of Thiago Macieira Sent: Thursday, June 05, 2014 11:43 AM To: interest@qt-project.org Subject: Re: [Interest] QtDBus Example to read files from USB Em qui 05 jun 2014, às 06:02:58, Ramakanthreddy Kesireddy escreveu: > Hi, > > Is there any Qt DBus example to read the files from USB? D-Bus is used to send and receive messages. It has nothing to do with USB. You may have a service in your system that can read files from USB. I don't know of any program that can do that for you. But if you do, please study its documentation and figure out what calls you need to place. If you don't know how to make the calls, we can help you. You just need to provide the interfaces, names of the methods and what parameters are necessary. -- Thiago Macieira - thiago.macieira (AT) intel.com Software Architect - Intel Open Source Technology Center _______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest ________________________________ DISCLAIMER: This email (including any attachments) is intended for the sole use of the intended recipient/s and may contain material that is CONFIDENTIAL AND PRIVATE COMPANY INFORMATION. Any review or reliance by others or copying or distribution or forwarding of any or all of the contents in this message is STRICTLY PROHIBITED. If you are not the intended recipient, please contact the sender by email and delete all copies; your cooperation in this regard is appreciated. ============================================================================================================================ Disclaimer: This message and the information contained herein is proprietary and confidential and subject to the Tech Mahindra policy statement, you may review the policy at http://www.techmahindra.com/Disclaimer.html externally http://tim.techmahindra.com/tim/disclaimer.html internally within TechMahindra. ============================================================================================================================
#include "usbdialog.h" #include "ui_usbdialog.h" #include <QDBusConnection> #include <QDBusMessage> #include <QDBusObjectPath> #include <QDebug> UsbDialog::UsbDialog(QWidget *parent) : QDialog(parent), ui(new Ui::UsbDialog) { ui->setupUi(this); initUSB(); connect(this,SIGNAL(connectUSBDevice(bool)),this,SLOT(setUSB(bool))); } UsbDialog::~UsbDialog() { delete ui; } void UsbDialog::setupDBus() { // Get the system bus QDBusConnection system = QDBusConnection::systemBus(); // check if it is connected if (!system.isConnected()) { qFatal("Cannot connect to the D-Bus session bus."); return; } // register "device added" Q_ASSERT(system.connect("org.freedesktop.UDisks", "/org/freedesktop/UDisks", "org.freedesktop.UDisks", "DeviceAdded", this, SLOT(deviceAdded(const QDBusObjectPath&)))); // register "device removed" Q_ASSERT(system.connect("org.freedesktop.UDisks", "/org/freedesktop/UDisks", "org.freedesktop.UDisks", "DeviceRemoved", this, SLOT(deviceRemoved(const QDBusObjectPath&)))); } // method to call dbus void UsbDialog::queryDevices() { QDBusConnection system = QDBusConnection::systemBus(); if (!system.isConnected()) { qFatal("Cannot connect to the D-Bus session bus."); return; } QDBusMessage message = QDBusMessage::createMethodCall("org.freedesktop.UDisks", "/org/freedesktop/UDisks", "org.freedesktop.UDisks", "EnumerateDevices"); // synchronous call (not recommended, blocking) QDBusMessage response = QDBusConnection::systemBus().call(message); //qDebug() << "response is: " << response; } // slot for "device added" void UsbDialog::deviceAdded(const QDBusObjectPath &in) { qDebug() << "device added: " << in.path(); emit connectUSBDevice(true); } // slot for "device removed" void UsbDialog::deviceRemoved(const QDBusObjectPath& in) { qDebug() << "device removed: " << in.path(); emit connectUSBDevice(false); } void UsbDialog::setUSB(bool isUSB) { qDebug()<<"usb is connected"; if(isUSB) this->setStyleSheet("background-color:yellow;"); else this->setStyleSheet("background-color:blue;"); } void UsbDialog::initUSB() { setupDBus(); queryDevices(); }
#ifndef USBDIALOG_H #define USBDIALOG_H #include <QDialog> #include <QDBusObjectPath> namespace Ui { class UsbDialog; } class UsbDialog : public QDialog { Q_OBJECT public: explicit UsbDialog(QWidget *parent = 0); ~UsbDialog(); public: void initUSB(); private: void setupDBus(); void queryDevices(); private slots: void deviceAdded(const QDBusObjectPath &in); void deviceRemoved(const QDBusObjectPath& in); void setUSB(bool); signals: void connectUSBDevice(bool); public: bool isUsbConnected; private: Ui::UsbDialog *ui; }; // // #endif // USBDIALOG_H
_______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest