×

Discussion Board

Results 1 to 8 of 8
  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    32

    Question Cannot send SMS the second time. Need help with QtMobility problem!

    Hi all,
    I'm developing a program for my final year project in Nokia using Qt. In that i need to send an sms using Qt Mobility. I used the code below
    mainwindow.cpp
    Code:
    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
        QObject::connect(&service,SIGNAL(stateChanged(QMessageService::State)),this,SLOT(stateChanged(QMessageService::State)));
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    
    void MainWindow::on_toolButton_clicked()
    {
        QMessage message;
        message.setType(QMessage::Sms);
        message.setTo(QMessageAddress(QMessageAddress::Phone,"+919791504579"));
        message.setBody("Hi this is the message");
        if(service.send(message))
        {
            QMessageBox::information(this,"","Message Sent!");
        }
    
    }
    
    void MainWindow::stateChanged(QMessageService::State s)
    {
        if(s==QMessageService::ActiveState)
            QMessageBox::information(this,"State","Active State");
        if(s==QMessageService::InactiveState)
            QMessageBox::information(this,"State","Inactive State");
        if(s==QMessageService::CanceledState)
            QMessageBox::information(this,"State","Cancelled State");
        else
            QMessageBox::information(this,"State","Finished");
    }
    mainwindow.h
    Code:
    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    
    #include <QMainWindow>
    #include <QMessage>
    #include <QMessageService>
    #include <QMessageAddress>
    #include <QMessageBox>
    
    QTM_USE_NAMESPACE
    
    namespace Ui {
        class MainWindow;
    }
    
    class MainWindow : public QMainWindow
    {
        Q_OBJECT
    
    public:
        explicit MainWindow(QWidget *parent = 0);
        ~MainWindow();
    
    private:
        Ui::MainWindow *ui;
        QMessageService service;
    
    private slots:
        void on_toolButton_clicked();
        void stateChanged(QMessageService::State);
    };
    
    #endif // MAINWINDOW_H
    and when clicking the button is shows that messsage is sent, but when I click the button for the second time the Application Output in the Qt Creator shows that Action is currently busy and after pressing the exit it shows this error
    QSqlDatabasePrivate::removeDatabase: connection 'qt_sql_default_connection' is still in use, all queries will cease to work.
    I think I,m using Qt Mobility version 4.6. Is there anything that I have done wrong. Kindly help me because I have less time to finish my final year project.

  2. #2
    Nokia Developer Expert
    Join Date
    Jul 2003
    Location
    Vancouver, Canada
    Posts
    220

    Re: Cannot send SMS the second time. Need help with QtMobility problem!

    You are creating your message object as an auto variable (i.e on the stack) and then it gets destroyed when your on_toolButton_clicked method exits. This is the problem. If you declare it as a member data for your class it will probably work as expected.

    QMessageService send takes a reference. As a general rules, unless documentation states otherwise, methods that take a reference require you to maintain the object in memory until the asynchronous operation notifies you that is has completed, usually via callback, or in this case the with QMessageService the stateChanged method will notify you with the 'finished' state

  3. #3
    Registered User
    Join Date
    Apr 2010
    Posts
    32

    Re: Cannot send SMS the second time. Need help with QtMobility problem!

    Thanks for the reply billbonney, I will try that and post the reply.

  4. #4
    Registered User
    Join Date
    Apr 2010
    Posts
    32

    Re: Cannot send SMS the second time. Need help with QtMobility problem!

    No, bill bonney, I have tried putting that message variable as a member of the MainWindow class but yet the problem is not resolved.

    I have also tried debugging the program, when i saw the debugging output, after sending the first message and after responding to all the Message Boxes it shows "Running". What would be the real cause?. Will it be some problem with the QtMobility version?

    I have tried that application installed in my device but no message is sent even for the first time. Does it requires any TARGET.CAPABILITY parameters? I have added the MOBILITY parameter networkservices and messaging.
    Last edited by ravi4frenz; 2011-01-02 at 16:04.

  5. #5
    Nokia Developer Expert
    Join Date
    Jul 2003
    Location
    Vancouver, Canada
    Posts
    220

    Re: Cannot send SMS the second time. Need help with QtMobility problem!

    A quick look at the quick start guide and a search for capabilties http://doc.qt.nokia.com/qtmobility-1...uickstart.html shows Messaging needs LocalServices ReadUserData WriteUserData NetworkServices UserEnvironment ReadDeviceData WriteDeviceData.

    Also this posting is quite helpful http://wiki.forum.nokia.com/index.ph...ng_Qt_Mobility

    and this one http://wiki.forum.nokia.com/index.php/Capabilities

    Hope that helps

  6. #6
    Registered User
    Join Date
    Apr 2010
    Posts
    32

    Re: Cannot send SMS the second time. Need help with QtMobility problem!

    Thank you for your hel;p. Yes, I have added those capabilities and still after trying to send the message for the second time, it puts the message in the sent folder directly. May be, this bug is going to be cleared in the future releases of Mobility API

  7. #7
    Registered User
    Join Date
    Jan 2011
    Posts
    1

    Re: Cannot send SMS the second time. Need help with QtMobility problem!

    I'm new to this forum, but let me try to guess the problem:
    -QMessageService::send is not sync call, i.e it might return false if something really problematic happened at early stage, like SMS destination number is not filled, but it does not signal about message sending. To be notified about send result, you have to connect to signal stateChanged(QMessageService::State).
    Moreover, QMessageService documentation tells, that only one entity can be processed at the moment, if one SMS is being sending, "sender" is busy. So, you have to wait until appropriate state and buffer your SMSes or return. State is checked with state() member.

  8. #8
    Registered User
    Join Date
    Apr 2010
    Posts
    32

    Re: Cannot send SMS the second time. Need help with QtMobility problem!

    I have checked using the MessageStateChanged and it shows that message is sent. but it appears in the sent folder like what we see in inbox nem message. Might be some problem with mobility apis.

Similar Threads

  1. How can we send sms after a specified TIME.
    By rahulkrishna in forum Mobile Java General
    Replies: 4
    Last Post: 2009-08-26, 14:12
  2. Time taken to send an sms.
    By kush_192 in forum Symbian
    Replies: 11
    Last Post: 2009-04-20, 11:43
  3. How to send more than one sms at a time.
    By girishvmx in forum Symbian Networking & Messaging (Closed)
    Replies: 10
    Last Post: 2008-02-20, 16:33
  4. To Send SMS more than one at a time
    By preethi in forum Symbian Networking & Messaging (Closed)
    Replies: 5
    Last Post: 2007-10-05, 16:21
  5. send sms to many at the same time
    By hanyen83 in forum General Messaging
    Replies: 0
    Last Post: 2004-03-20, 07:47

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×