Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Application crashed with Message Box.
Forum Updated to NodeBB v4.3 + New Features

Application crashed with Message Box.

Scheduled Pinned Locked Moved General and Desktop
9 Posts 4 Posters 3.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    psbhardwaj09gmail.com
    wrote on last edited by
    #1

    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

    Pardeep Sharma

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      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.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • G Offline
        G Offline
        giesbert
        wrote on last edited by
        #3

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

        Nokia Certified Qt Specialist.
        Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

        1 Reply Last reply
        0
        • P Offline
          P Offline
          psbhardwaj09gmail.com
          wrote on last edited by
          #4

          Hi Gerolf

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

          Pardeep Sharma

          1 Reply Last reply
          0
          • raven-worxR Offline
            raven-worxR Offline
            raven-worx
            Moderators
            wrote on last edited by
            #5

            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.

            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
            If you have a question please use the forum so others can benefit from the solution in the future

            1 Reply Last reply
            0
            • C Offline
              C Offline
              chris17
              wrote on last edited by
              #6

              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

              1 Reply Last reply
              0
              • P Offline
                P Offline
                psbhardwaj09gmail.com
                wrote on last edited by
                #7

                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.

                Pardeep Sharma

                1 Reply Last reply
                0
                • P Offline
                  P Offline
                  psbhardwaj09gmail.com
                  wrote on last edited by
                  #8

                  Can anybody help me for this?

                  Pardeep Sharma

                  1 Reply Last reply
                  0
                  • C Offline
                    C Offline
                    chris17
                    wrote on last edited by
                    #9

                    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;
                    }
                    @

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved