Bug 358261 - SMS messages list is not update when calling ModemManager::ModemMessaging::createMessage
Summary: SMS messages list is not update when calling ModemManager::ModemMessaging::cr...
Status: RESOLVED NOT A BUG
Alias: None
Product: frameworks-modemmanager-qt
Classification: Frameworks and Libraries
Component: general (show other bugs)
Version: unspecified
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Jan Grulich
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-01-20 15:40 UTC by Daniel
Modified: 2016-01-22 11:32 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel 2016-01-20 15:40:59 UTC
In order to send SMS using the modemmanagerqt api it is necessary to first create a message, after that find that message in SMS list and then send.

After creating a message using QDBusPendingReply<QDBusObjectPath> ModemManager::ModemMessaging::createMessage(const Message &message) the message list accessible from ModemManager::Sms::List ModemManager::ModemMessaging::messages() is not modified and didn't contains the new message recently created.

Reproducible: Always

Steps to Reproduce:
1. Get a valid instance of a ModemDevice: ModemManager::ModemDevice::Ptr modemdevice;
2. Get the messaging interface: ModemManager::ModemMessaging::Ptr messaging = modemdevice->messagingInterface();
3. Create a valid message: ModemManager::ModemMessaging::Message msg;
            msg.number = "validnumber";
            msg.text = "Hello World!";
4. Try to create a message: QDBusPendingReply<QDBusObjectPath> sms = messaging->createMessage(msg);
5. Wait for pending reply: sms.waitForFinished();
6. Check the validity of the reply: if ( sms.isValid() )
7. Iterate over the list of valid sms messages: ModemManager::Sms::List messages = messaging->messages();
Q_FOREACH (ModemManager::Sms::Ptr sms, messages) {
    qDebug() << "   " << sms->number() << sms->text() << sms->uni();
}
8. The new created message will not present in the list.

Actual Results:  
The new created message will not present in the list.

Expected Results:  
The new created message will present in the list.
Comment 1 Lamarque V. Souza 2016-01-20 16:25:53 UTC
Hi, MMQt API is assynchronous and MMQt needs to receive signals from ModemManager to update the message list. That is probably not happening because you are doing everything in synchronous mode. Try adding the line below after *before* step 7 and check if your example works:

// Include QCoreApplication if compiler complains about qApp not defined.
qApp->processEvents();

That will make Qt process any pending event (like ModemManager's signal to update the message list).

If that works then you need to update your code to work in asynchronous mode. Using processEvent() must be avoided since it is a costly method call.
Comment 2 Daniel 2016-01-20 17:18:27 UTC
Even using the qApp->processEvents(); as you suggested, the message list was not updated after that.

But as you warned me that I am using in a synchronous mode, I changed the way to use, now I am using signal/slots and I connected the signal ModemManager::ModemMessaging::messageAdded in a custom slot and this signal is emitted OK and I can access the recently created message using the messages property (ModemManager::Sms::List messages = messaging->messages()). It means that the list contains the recently added message inside the slot called by the signal.

Probably I am misusing the framework MMQt. I based my code in the source code of the example folder. In the truth that example didn't work for me. Running the example the message did not sent. Is the example running for you?

If you like I can contribute with the MMQt in order to provide more examples.

Thanks in advance. (Sorry for my english, I am from Brazil).
Comment 3 Daniel 2016-01-20 17:26:31 UTC
Adding 

qApp->processEvents();
qApp->processEvents();

instead of just one, make the things work.
Comment 4 Jan Grulich 2016-01-20 17:57:22 UTC
Using signals and slots is the way how to use both MMQT and NMQT properly. Do not pay attention that much to the example, I was lazy to write a proper one and that one you see was created just as a testing code for sending sms.

If you want any help with MMQT API just contact us on kde-hardware-devel@kde.org mailing list and we will be more than happy to help you and don't worry about your english, most of us are not native speakers (I'm from Czech Republic and Lamarque is from Brazil too).
Comment 5 Daniel 2016-01-22 09:57:24 UTC
Thank you for the answers. I sent a message in the kde-hardware-devel list.