USB detection using QDBusConnection API
I'm using QDBusConnecton API to detect USB.
The code is:
mainwindow.cpp
Code:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDBusConnection>
#include <QDebug>
MainWindow
::MainWindow(QWidget *parent
){
ui->setupUi(this);
qDebug() << "Cannot connect to system bus";
}
"org.freedesktop.UDisks",
"/org/freedesktop/UDisks",
"org.freedesktop.UDisks",
"DeviceAdded",
}
MainWindow::~MainWindow()
{
delete ui;
}
{
qDebug() << "device added!"<<dev.path();
}
mainwindow .h
Code:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QtGui/QApplication>
namespace Ui {
class MainWindow;
}
Q_OBJECT
public:
explicit MainWindow
(QWidget *parent
= 0);
~MainWindow();
private:
Ui::MainWindow *ui;
private slots:
};
#endif // MAINWINDOW_H
I'm getting error as:
mainwindow.cpp:3:27: fatal error: ui_mainwindow.h: No such file or directory
compilation terminated.
Please tell me is there any mistake in this code?
how to solve this Issue?
Re: USB detection using QDBusConnection API
How did you generate the ui_mainwindow.h ??
Check the spelling and make sure it is the same file.
Re: USB detection using QDBusConnection API
My application is not generating ui_mainwindow.h file.
How to generate that file?
Is there any path should I need to include in .pro file to generate ui_mainwindow.h file?
Re: USB detection using QDBusConnection API
A ui_something.h file is the result of user interface code generated by UIC from a .ui file (qt Designer file) with the same name.
This UI file has to be listed in the FORMS variable in the .pro file.
If you don't have a .ui file I wonder how you got the include and the code using it in the first place.
Cheers,
_
Re: USB detection using QDBusConnection API
I have made modifications and using the following code:
Code:
#include <QtCore/QDebug>
#include <QtGui/QApplication>
#include <QtDBus/QDBusConnection>
#define HAL_SERV "org.freedesktop.Hal"
#define HAL_MGR_INT "org.freedesktop.Hal.Manager"
#define HAL_DEV_INT "org.freedesktop.Hal.Device"
#define HAL_MGR_PATH "/org/freedesktop/Hal/Manager"
#define HAL_DEVS_PATH "/org/freedesktop/Hal/devices"
{
Q_OBJECT;
public:
Hal() :
{
cnx.connect(
HAL_SERV, HAL_MGR_PATH, HAL_MGR_INT, "DeviceAdded",
cnx.connect(
HAL_SERV, HAL_MGR_PATH, HAL_MGR_INT, "DeviceRemoved",
}
private slots:
{
qDebug() << __FUNCTION__ << dev;
}
{
qDebug() << __FUNCTION__ << dev;
}
private:
};
int main( int ac, char * * av )
{
Hal hal;
return( app.exec() );
}
#include "main.moc"
By using above code,connection is successful,but it not receiving the signal even USB connected to the system.Anyone can help me regarding this?
Re: USB detection using QDBusConnection API
Try attaching and removing the usb at runtime. The signals are meant for that.
If the usb is already attached to the system , I am afraid that the signal will be emitted when your app connects to it.
You will probably need to query some function for the list of usb devices connected at the start-up of your application.
Re: USB detection using QDBusConnection API
I have tried by connecting and removing USB, even though Not detecting the USB,not receiving the signals.
It should detect any devices right? any mistakes I did?
Re: USB detection using QDBusConnection API
Have you checked the return values of your connect() calls?
Does your system run the HAL service?
Cheers,
_
Re: USB detection using QDBusConnection API
yes the bus connect function returning true,but signal is not emitting.
and How to check our system is able to service HAL?
Is there I need to install any packages regarding this?
Right now ubuntu has hal-info 20091130-1.
Re: USB detection using QDBusConnection API
The connects would likely fail if it were not running, but you can check yourself, e.g. by running
qdbus --system
to list all service registered with the system bus.
You could also check if the service is actually emitting the signal, i.e. if the problem is on your side or not
dbus-monitor --system "type='signal',sender='org.freedesktop.Hal',interf ace='org.freedesktop.Hal.Manager'"
Cheers,
_