×
Namespaces

Variants
Actions
(Difference between revisions)

QML SMShelper Plugin

From Nokia Developer Wiki
Jump to: navigation, search
vineet.jain (Talk | contribs)
(Vineet.jain -)
hamishwillee (Talk | contribs)
m (Hamishwillee - Add SMS category. Fix code fragment)
Line 1: Line 1:
[[Category:Qt]][[Category:Qt Mobility]][[Category:Qt Quick]][[Category:Symbian]]
+
[[Category:Qt]][[Category:Qt Mobility]][[Category:Qt Quick]][[Category:Symbian]][[Category:SMS]]
__NOTOC__
+
{{Abstract|SMSplugin to expose Qt mobility SMS APIs to QML environment}}
__NOEDITSECTION__
+
__NOTOC__ __NOEDITSECTION__
 
{{ArticleMetaData
 
{{ArticleMetaData
 
|platform=Symbian^3  
 
|platform=Symbian^3  
 
|devices=N8, E7, C7  
 
|devices=N8, E7, C7  
|creationdate=29.04.2011
+
|creationdate=20110429
|keywords=QML, SMS, Messaging
+
|keywords=QMessageService, QMessageManager
 
|sourcecode= [[Media:Smssender.zip]]
 
|sourcecode= [[Media:Smssender.zip]]
 
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
 
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
|sdk=<!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) -->
+
|sdk=[http://qt.nokia.com/downloads Qt SDK] 4.7.1 or newer and [http://qt.nokia.com/products/qt-addons/mobility Qt mobility] 1.1.0 or newer
 
|devicecompatability=<!-- Compatible devices (e.g.: All* (must have GPS) ) -->
 
|devicecompatability=<!-- Compatible devices (e.g.: All* (must have GPS) ) -->
 
|signing=Self-Signed
 
|signing=Self-Signed
Line 15: Line 15:
 
|author=[[User:Jahartik]]
 
|author=[[User:Jahartik]]
 
}}
 
}}
 
==Overview==
 
 
{{Abstract|SMSplugin to expose Qt mobility SMS APIs to QML environment}}
 
 
This snippet can be self-signed.
 
 
==Preconditions==
 
 
[http://qt.nokia.com/downloads Qt SDK]4.7.1 or newer and [http://qt.nokia.com/products/qt-addons/mobility Qt mobility] 1.1.0 or newer installed
 
  
 
==Pro file==
 
==Pro file==
Line 85: Line 75:
  
 
#endif // SMSHELPER_H
 
#endif // SMSHELPER_H
 
 
</code>  
 
</code>  
  
Line 110: Line 99:
 
{
 
{
 
}
 
}
 
  
  
Line 189: Line 177:
  
 
Example use QML
 
Example use QML
<code cpp>  
+
<code css>  
 
SMSHelper
 
SMSHelper
 
     {
 
     {
 
         id: smshelper
 
         id: smshelper
----
+
}
SMShelper developer APIs
+
</code>
  
Constructor and destructor
+
== SMShelper developer APIs ==
 +
 
 +
<code cpp>
 +
//Constructor and destructor
 
SMSHelper(QObject *parent = 0);
 
SMSHelper(QObject *parent = 0);
 
~SMSHelper();
 
~SMSHelper();
  
Public slots:
+
public slots:
 
sendsms(QString phonenumber, QString message);
 
sendsms(QString phonenumber, QString message);
  
Public signals
+
signals:
 
void stateMsg(const QString &statemsg);
 
void stateMsg(const QString &statemsg);
 
void errorMsg(const QString &errormsg);
 
void errorMsg(const QString &errormsg);
 
void debugMsg(const QString &dbgmsg);
 
void debugMsg(const QString &dbgmsg);
 
</code>
 
</code>

Revision as of 02:22, 13 December 2011

SMSplugin to expose Qt mobility SMS APIs to QML environment

Article Metadata
Code Example
Source file: Media:Smssender.zip
Tested with
SDK: Qt SDK 4.7.1 or newer and Qt mobility 1.1.0 or newer
Devices(s): N8, E7, C7
Compatibility
Platform(s): Symbian^3
Platform Security
Signing Required: Self-Signed
Capabilities: NetworkServices
Article
Keywords: QMessageService, QMessageManager
Created: jahartik (29 Apr 2011)
Last edited: hamishwillee (13 Dec 2011)

Pro file

The following capabilities and libraries are required:

symbian:TARGET.CAPABILITY = NetworkServices
CONFIG += mobility
MOBILITY = messaging

Header file

smshelper.h applying this macro to definitions of member functions to allow them to be invoked via the meta-object system

#ifndef SMSHELPER_H
#define SMSHELPER_H
 
#include <QObject>
#include <qmessage.h>
#include <qmessageservice.h>
 
QTM_USE_NAMESPACE
 
 
#ifdef Q_OS_SYMBIAN
# define SENDSMS_ENABLED
#elif defined(Q_WS_MAEMO_5) || defined(Q_WS_MAEMO_6)
# define SENDSMS_ENABLED
#endif
 
class SMSHelper : public QObject
{
Q_OBJECT
 
public:
explicit SMSHelper(QObject *parent = 0);
~SMSHelper();
 
Q_INVOKABLE bool sendsms(QString phonenumber, QString message);
 
signals:
void stateMsg(const QString &statemsg);
void errorMsg(const QString &errormsg);
void debugMsg(const QString &dbgmsg);
 
private slots:
void messageStateChanged(QMessageService::State s);
#ifndef SENDSMS_ENABLED
void signalFinishedState() { emit stateMsg("FinishedState");};
#endif
private:
QMessageService iMessageService;
QMessageManager iManager;
QMessageService::State state;
 
 
};
 
#endif // SMSHELPER_H


Source file

smshelper source code

#include "smshelper.h"
 
#ifndef SENDSMS_ENABLED
#include <QTimer>
#endif
 
SMSHelper::SMSHelper(QObject *parent) :
QObject(parent)
{
state = QMessageService::InactiveState;
connect(&iMessageService, SIGNAL(stateChanged(QMessageService::State)), this, SLOT(messageStateChanged(QMessageService::State)));
 
}
 
SMSHelper::~SMSHelper()
{
}
 
 
bool SMSHelper::sendsms(QString phonenumber, QString message)
{
 
#ifdef SENDSMS_ENABLED
if (!QMessageAccount::defaultAccount(QMessage::Sms).isValid())
{
emit errorMsg("No messageaccount for sms sending.");
return false;
}
 
if (state == QMessageService::InactiveState || state == QMessageService::FinishedState)
{
QMessage sms;
 
sms.setType(QMessage::Sms);
sms.setParentAccountId(QMessageAccount::defaultAccount(QMessage::Sms));
sms.setTo(QMessageAddress(QMessageAddress::Phone, phonenumber));
sms.setBody(message);
 
return iMessageService.send(sms);
}
else
{
return false;
}
 
#else
QTimer::singleShot(1000,this,SLOT(signalFinishedState()));
return true;
#endif
 
 
 
}
 
void SMSHelper::messageStateChanged(QMessageService::State s)
{
state = s;
 
if (s == QMessageService::InactiveState)
{
emit stateMsg("InactiveState");
}
else if (s == QMessageService::ActiveState)
{
emit stateMsg("ActiveState");
}
else if (s == QMessageService::CanceledState)
{
emit stateMsg("CanceledState");
}
else if (s == QMessageService::FinishedState)
{
emit stateMsg("FinishedState");
}
else
{
emit stateMsg(QString("QMessageService::%1").arg(s));
}
}

To register the C++ type in the QML system with the name SMSHelper include following code in your main.cpp file

qmlRegisterType<SMSHelper>("SMSHelper",1,0,"SMSHelper");

Import sms plugin in QML

import SMSHelper 1.0

Example use QML

SMSHelper
{
id: smshelper
}

SMShelper developer APIs

//Constructor and destructor
SMSHelper(QObject *parent = 0);
~SMSHelper();
 
public slots:
sendsms(QString phonenumber, QString message);
 
signals:
void stateMsg(const QString &statemsg);
void errorMsg(const QString &errormsg);
void debugMsg(const QString &dbgmsg);
163 page views in the last 30 days.
×