Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Contributor
Posts: 10
Registered: ‎11-02-2012
My Device: BB10
My Carrier: many

Using MessageService from cascades in native applications

Hello!

I'm currently writing some code to send and receive SMS from a native application, I been able to successfully send a SMS using MessageService from cascades (note that this isn't a pure cascades application), but when I try to use the messageAdded(AccountKey,ConversationKey, MessageKey) function I don't get the signal triggered when a new SMS arrives.

 

 

 I can successfully connect the the signal using: 

 

bool res = connect(m_messageService, SIGNAL(messageAdded(bb::pim::account::AccountKey, bb::pim::message::ConversationKey, bb::pim::message::MessageKey)), SLOT(onNewSms()));

fprintf(stderr,"\nConnect result messageAdded:%s",(res?"OK":"FAIL"));

 

where m_messageService is an instance to bb:Smiley Tongueim::message::MessageService, and onNewSms() is the slot function I want to call when the message is received, this m_messageService is the same instance I use to send SMS.

 

The message handling class is quite simple:


#include <QObject> #include <bb/pim/account/Account> #include <bb/pim/message/MessageService> class SmsHandler : public QObject { Q_OBJECT public: SmsHandler(); virtual ~SmsHandler(); void sendSMS(QString regID, QString contactNumber);//sends a new SMS to contactNumber

private Q_SLOTS: void onNewSms(); //this should be called when we have a new SMS private: bb::pim::message::MessageService* m_messageService; bb::pim::account::Account m_currentAccount; };

 

In order to compile this last code I manually call moc from %QNX_HOST%\usr\bin to generate a moc_SmsHandler.cpp file.

So, long story short, I can successfully send a SMS from a native application (again, from a non-cascades application) but messageAdded isn't triggered when a new SMS arrives. Does anyone knows if I need to do something else to get the signal triggered in non cascades apps?

 

Additional notes:

+ The onNewSms slot is called when I send a new SMS from the device, this leads me to think that the SLOTS/SIGNALS of cascades can be used from non-cascades applications.

+ The signal is correctly triggered in a 100% cascades app. Again, do I need to do something else for non-cascades applications?

 

Sorry for the long post, I just wanted to told you beforehand what  was already done.

Thanks in advance.

 

Retired
Posts: 571
Registered: ‎06-25-2010
My Device: Z10
My Carrier: Vodafone

Re: Using MessageService from cascades in native applications

[ Edited ]

I use messageAdded without problem. My connect statement looks like this:

 

 

connect(_message_service,
    SIGNAL(
        messageAdded(bb::pim::account::AccountKey, bb::pim::message::ConversationKey, bb::pim::message::MessageKey)),    
    SLOT( 
        messageReceived(bb::pim::account::AccountKey, bb::pim::message::ConversationKey, bb::pim::message::MessageKey)));

 

 

When an SMS arrives, the slot receives a callback.

 

I wrote a knowledge base article on SMS APIs by the way:

 

http://supportforums.blackberry.com/t5/Native-Development/BlackBerry-10-Developer-s-Guide-to-SMS/ta-...  

 

Regards

 

Martin

--------------------------------------------------------------------------------------------
Feel free to press the like button on the right side if you liked my attempts to help :-)
And please mark posts as solved if you think I found the solution or set you on its path. Thanks!
Follow me on Twitter: @mdwrim
Contributor
Posts: 10
Registered: ‎11-02-2012
My Device: BB10
My Carrier: many

Re: Using MessageService from cascades in native applications

[ Edited ]

Thanks!  Good tutorial on SMS too, however, I'm trying to get the signals fired from a native non cascades application, like the ones you get when you do a "New Screen Project", i'm able to send SMS from here but not able to trigger the signal. If I do a 100% cascades application I do get the signal fired, but going 100% cascades doesn't fit my needs.

Retired
Posts: 571
Registered: ‎06-25-2010
My Device: Z10
My Carrier: Vodafone

Re: Using MessageService from cascades in native applications

Glad you like the tutorial :-)

 

I'm guessing your problem is not so much about Cascades as it is about Qt. For signals/slots to work, your class must extend QObject. Is that the case?

--------------------------------------------------------------------------------------------
Feel free to press the like button on the right side if you liked my attempts to help :-)
And please mark posts as solved if you think I found the solution or set you on its path. Thanks!
Follow me on Twitter: @mdwrim
Contributor
Posts: 10
Registered: ‎11-02-2012
My Device: BB10
My Carrier: many

Re: Using MessageService from cascades in native applications

The SMS part does extend QObject but it just handles SMS (no layout, no screens), but the  main loop is not a bb/cascades/Application.

Retired
Posts: 571
Registered: ‎06-25-2010
My Device: Z10
My Carrier: Vodafone

Re: Using MessageService from cascades in native applications

[ Edited ]

Do you use the Q_OBJECT macro in your header file? Sorry if these are obvious questions you already checked.

 

Are there any errors in the logs? slog2info will display the logs from an ssh session to your BlackBerry 10 device. See if there are any errors relating to your connect statement. The most common issue I've had with signals and slots concerned having my connect statement wrong in some way.

 

Try cleaning your project btw as this will ensure the MOC processor gets re-run against the Q_OBJECT macro.

 


 

 

UPDATE: I just noticed that your slot method has no arguments. I think it needs to have the same signature (parameters and types) as the signal. See http://qt-project.org/wiki/Qt_for_beginners_Signals_and_slots where it says:

 

"

You can see that the signal and the slot have the same kind of parameters, especially the type. If you connect a signal to a slot that do not share the same kind of parameters, while the connection is done (at run-time) you will get a warning like


QObject::connect: Incompatible sender/receiver arguments

It is because the signal transmits the information to the slot using the parameters. The first parameter of the signal is passed to the first one of the slot, and the same for second, third, and so forth."

 

--------------------------------------------------------------------------------------------
Feel free to press the like button on the right side if you liked my attempts to help :-)
And please mark posts as solved if you think I found the solution or set you on its path. Thanks!
Follow me on Twitter: @mdwrim
Regular Contributor
Posts: 205
Registered: ‎06-11-2013
My Device: Blackbery z10
My Carrier: RIM

Re: Using MessageService from cascades in native applications

I have the similar question.

Retired
Posts: 571
Registered: ‎06-25-2010
My Device: Z10
My Carrier: Vodafone

Re: Using MessageService from cascades in native applications

Your "similar question" is that you do not get the messageAdded signal fired?

 

Can you elaborate on your question please and post the related code?

 

Thanks

--------------------------------------------------------------------------------------------
Feel free to press the like button on the right side if you liked my attempts to help :-)
And please mark posts as solved if you think I found the solution or set you on its path. Thanks!
Follow me on Twitter: @mdwrim