Archived:How to read IMEI in Qt application for Maemo 5
The IMEI should be accessed using the cross platform Qt Mobility API QSystemDeviceInfo
Article Metadata
Archived: This article shows how to use the Maemo 5 DBus interface for obtaining IMEI of the phone.
The name of a service is com.nokia.phone.SIM, a path name is /com/nokia/phone/SIM/security, an interface name is Phone.Sim.Security. Finally the method's name responsible for obtaining IMEI is get_imei
You can verify that it works using dbus-send utility in XTerm:
dbus-send --system --type=method_call --print-reply \
--dest=com.nokia.phone.SIM \
/com/nokia/phone/SIM/security \
Phone.Sim.Security.get_imei
Now how you do it with C++ and Qt. First you need to create an interface on system bus identified by service/path/interface triad. A next step is to perform a method call to obtain a reply. Note that the call is synchronous, i.e., blocking. This is simple example and lightweight call, for more serious tasks use QDBusAbstractInterface::callWithCallback(). Reply contains string and integer value. The former represents IMEI of the phone.
#include <QApplication>
#include <QLabel>
#include <QDBusInterface>
#include <QDBusMessage>
#include <QDebug>
#define SIM_DBUS_SERVICE "com.nokia.phone.SIM"
#define SIM_DBUS_PATH "/com/nokia/phone/SIM/security"
#define SIM_DBUS_IFACE "Phone.Sim.Security"
#define SIM_IMEI_REQ "get_imei"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QLabel label;
label.setAlignment(Qt::AlignCenter);
label.setFont(QFont("Nokia Sans", 35, QFont::Bold));
label.show();
QDBusInterface interface(SIM_DBUS_SERVICE, SIM_DBUS_PATH, SIM_DBUS_IFACE,
QDBusConnection::systemBus());
QDBusMessage reply = interface.call(SIM_IMEI_REQ);
if (reply.type() == QDBusMessage::ErrorMessage)
qDebug() << reply.errorMessage();
else {
QList<QVariant> args = reply.arguments();
qDebug() << args;
label.setText(QString("Phone's IMEI: %1").arg(args.at(0).toString()));
}
return a.exec();
}

