Application crashed with Message Box.



  • Hi,

    I have an application in which i am using Message Box, which closed after 3 seconds automatically, to display some information. Now problem is that if i get any other callback within closing time of MessageBox, then my application get crashed.
    Code which i used is as following
    .h file
    @class ToastMessageBox : public QMessageBox
    {
    Q_OBJECT
    public:
    ToastMessageBox(const QString &msg, const QString &title, const QString &toastType = NULL);

    public:
    static void popup(const QString &msg, const QString &title, const QString &toastType = NULL);
    };
    @

    .cpp file

    @
    #include "ToastMessageBox.h"
    #include <QLabel>
    #include <QPushButton>
    #include <QVBoxLayout>
    #include <QTimer>
    #include <QTextEdit>

    ToastMessageBox::ToastMessageBox(const QString &msg, const QString &title, const QString &toastType)
    {
    setWindowTitle(title);
    setText(msg);
    if(toastType == "Information")
    {
    setIcon(QMessageBox::Information);
    }
    else if (toastType == "Warning")
    {
    setIcon(QMessageBox::Warning);
    }
    else
    {
    setIcon(QMessageBox::Critical);
    }

    //Setup the timer object with an interval of one second
    QTimer *pPopupCloseTimer = new QTimer(); //Construct the timer
    pPopupCloseTimer->setInterval(3000); //One second interval
    pPopupCloseTimer->setSingleShot(false); //Multiple shot. This means that the signal timeout will be signed each second
    pPopupCloseTimer->start();
    
    connect(pPopupCloseTimer,SIGNAL(timeout()),this,SLOT(close())); //Connects the timeout signal to my slot timeOut
    

    }

    void ToastMessageBox::popup(const QString &msg, const QString &title, const QString &toastType)
    {
    ToastMessageBox *pPopup = new ToastMessageBox(msg, title, toastType);
    pPopup->exec();
    }

    @

    and i am using it as

    @ToastMessageBox::popup("Some Information", "critical", "critical");@

    So can any one suggest me that how to solve this problem.

    Rgds,
    Pardeep Sharma


  • Moderators

    how should anyone help you without showing at least a few lines of code?!
    You can't expect someone to help you find a coding error with 3 sentences describing what your application does.



  • What do you mean by any other callback?
    What type of callback?
    From where does it come?



  • Hi Gerolf

    Callback came from middleware to do some other work like to open new window.


  • Moderators

    why don't you call the QMessageBox constructor in your derived class constructor?!

    and you should use:
    @const QString &toastType = QString();@
    instead of assigning NULL as default parameter since you're using a reference, not a pointer.



  • why do you set the timer to multishot, closing the messagebox more than once?

    maybe the crash happens because the messagebox and the timer never get deleted



  • Hi,

    Sorry for not detailing the problem. Let me explain you again the problem:

    I am working on sip based call application. I have a ToastMessageBox as shown above.

    So lets take two case Hold and disconnect
    @
    ApplicationManager::Hold(bool onHold)
    {

    if(onHold)
    {
    callview->Hold();
    }
    }

    callview::Hold(bool onHold)
    {
    ToastMessageBox::popup(tr("Call on Hold"), "Information", "Information");
    callview->enableResumeButton();
    }

    ApplicationManager::Disconnect()
    {
    delete callview;
    }
    @

    So now the middleware sends me callback for hold ,resume ,disconnect etc.

    So if i get Callback for hold i show the toastmessage and it return to same point after 3 sec. In the mean time(i dont want it a blocking popup) if i get disconnect event i delete the callview and
    after 3 sec when it comes to enableResumeButton the callview is deleted and so it crash.

    So is there any way to show it asyncronously or can you please suggest me something.



  • Can anybody help me for this?



  • If i get this right, the crash happens because you call enableResumebutton() on the already deleted callview object.

    is callview a subclass of QObject?
    does enableResetButton have to be called after the messagebox is closed?

    if you have to call enableResetButton you just need to make sure the pointer is still valid.

    you could try it like this:
    @
    callview::Hold(bool onHold)
    {
    ToastMessageBox::popup(tr("Call on Hold"), "Information", "Information");
    if(callview)
    {
    callview->enableResumeButton();
    }
    }

    ApplicationManager::Disconnect()
    {
    delete callview;
    callview=0;
    }
    @


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.