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 crashes when exception is raised

Application crashes when exception is raised

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.1k Views
  • 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.
  • A Offline
    A Offline
    avallabh88
    wrote on last edited by
    #1

    I have developed a application using Qt 5.3. I am using try catch block to handle the exceptions. So whenever there is an exception I am trying to show a QMessageBox to the user with a relevant message. This message is shown to the user but after 2 or 3 seconds the application crashes(Mainwindow crashes). I went through a couple of posts which recommended to override QApplication::notify() method to handle exceptions. I have overriden the method and still the same issue.Did anyone face this issue before? What is that I am missing here.This is the code I am using:

    main.cpp
    @
    #include "mainwindow.h"
    #include <QApplication>
    #include <ctime>
    #include <iostream>
    #include <QPixmap>
    #include <stdio.h>
    #include <QProcess>
    #include <QString>
    #include <tango.h>
    #include <QPainter>
    #include <QPen>
    #include <QBrush>
    #include <QLabel>
    #include <QTimer>
    #include <ctime>
    #include <QMessageBox>

    class Application final : public QApplication {
    Application(int& argc, char** argv) : QApplication(argc, argv) {}
    virtual bool notify(QObject *receiver, QEvent *e) override {
    // your code here

        try
            {
                return QApplication::notify( receiver, e );
            }
            catch(Tango::DevFailed e)
            {
              //some message
            }
            catch(Tango::CommunicationFailed e)
            {
                //some message
            }
    
    }
    

    };

    int main(int argc, char *argv[]) try
    {
    QApplication a(argc, argv);
    MainWindow w;
    w.show();

    return a.exec&#40;&#41;;
    

    }

    catch (Tango::DevFailed e)
    {
    //QMessageBox::information(this,tr("Updating values failed"),tr("Error updating values.Try again."));
    }
    catch (Tango::CommunicationFailed e)
    {
    //QMessageBox::information(this,tr("Communication Failed"),tr("Error updating values.Try again."));
    }

    @

    updatescreen.cpp
    @
    void updatescreen::on_pushButton_clicked()
    {
    //update values

      if(!ui->lineEdit_15->text().isEmpty())
      {
         //update method called
    

    //if method fails then error is thrown by the method in API which is handled by the QApplicatoin::notify in the main.cpp

      }
    

    }
    @

    Could you let me know what would be the reason for application crash. I followed many posts but could not resolve it.Thanks.

    [Added @ around code. andreyc]

    1 Reply Last reply
    0
    • D Offline
      D Offline
      Dima Rodionov
      wrote on last edited by
      #2

      You should instantiate your own application class, not QApplication in the main function. Given that your class with the notify(..) method reimplemented is called Application the main should look like this:

      int main(int argc, char* argv[])
      {
          Application app(argc, argv);
          MainWindow w;
      
          w.show();
      
          return app.exec;
      }
      
      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