Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Error: The program has unexpectedly finished.
Qt 6.11 is out! See what's new in the release blog

Error: The program has unexpectedly finished.

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 3 Posters 4.9k 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.
  • AhtiA Offline
    AhtiA Offline
    Ahti
    wrote on last edited by Ahti
    #1

    Why after initializing "home" pointer by calling "setupWidgets(home,homepanelShadow,homepanel,50,":/Images/Home.png");
    "
    it crashes on this statement :- "home->setStyleSheet("background-color:red;"); // this is where it crashes"
    below is the code :-

    ramadantimes.cpp

    RamadanTimes::RamadanTimes(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::RamadanTimes)
    {
        ui->setupUi(this);
        setupWidgets(home,homepanelShadow,homepanel,50,":/Images/Home.png");
        home->setStyleSheet("background-color:red;");  // this is where it crashes   
    }
    void RamadanTimes::setupWidgets(QToolButton *button,QGraphicsDropShadowEffect *panelshadow,
                                       QFrame *panel,int w,QString image){
    
        button = constructButton(button,w,image);
        panelshadow = createShadow(panelshadow,0,0,5);
        panel = constructFrame(panel,panelshadow);
    
        if (w != 50)
            panel->hide();
    }
    
    
    QToolButton *RamadanTimes::constructButton(QToolButton *button,int y,QString image){
    
        button = new QToolButton(menubar);
        button->setGeometry(0,y,60,50);
        button->setIcon(QIcon(image));
        button->setIconSize(QSize(35,35));
        button->setToolButtonStyle(Qt::ToolButtonIconOnly);
        button->setText("Home");
        button->setAutoRaise(true);
        button->setAutoRepeat(false);
        button->setStyleSheet("QToolButton:pressed { background-color: rgb(42,52,62); border:0px;}");
        return button ;
    }
    
    QGraphicsDropShadowEffect *RamadanTimes::createShadow(QGraphicsDropShadowEffect *shadow,int x, int y, int radius, QString color){
    
        shadow = new QGraphicsDropShadowEffect ;
        shadow->setXOffset(x);
        shadow->setYOffset(y);
        shadow->setBlurRadius(radius);
        shadow->setColor(color);
        return shadow ;
    }
    
    QFrame *RamadanTimes::constructFrame(QFrame *frame,QGraphicsDropShadowEffect *shadow){
    
        frame = new QFrame(this);
        frame->setGeometry(75,70,515,440);
        frame->setGraphicsEffect(shadow);
        return frame ;
    }
    
    

    what is a signature ?? Lol

    E 1 Reply Last reply
    0
    • AhtiA Ahti

      Why after initializing "home" pointer by calling "setupWidgets(home,homepanelShadow,homepanel,50,":/Images/Home.png");
      "
      it crashes on this statement :- "home->setStyleSheet("background-color:red;"); // this is where it crashes"
      below is the code :-

      ramadantimes.cpp

      RamadanTimes::RamadanTimes(QWidget *parent) :
          QMainWindow(parent),
          ui(new Ui::RamadanTimes)
      {
          ui->setupUi(this);
          setupWidgets(home,homepanelShadow,homepanel,50,":/Images/Home.png");
          home->setStyleSheet("background-color:red;");  // this is where it crashes   
      }
      void RamadanTimes::setupWidgets(QToolButton *button,QGraphicsDropShadowEffect *panelshadow,
                                         QFrame *panel,int w,QString image){
      
          button = constructButton(button,w,image);
          panelshadow = createShadow(panelshadow,0,0,5);
          panel = constructFrame(panel,panelshadow);
      
          if (w != 50)
              panel->hide();
      }
      
      
      QToolButton *RamadanTimes::constructButton(QToolButton *button,int y,QString image){
      
          button = new QToolButton(menubar);
          button->setGeometry(0,y,60,50);
          button->setIcon(QIcon(image));
          button->setIconSize(QSize(35,35));
          button->setToolButtonStyle(Qt::ToolButtonIconOnly);
          button->setText("Home");
          button->setAutoRaise(true);
          button->setAutoRepeat(false);
          button->setStyleSheet("QToolButton:pressed { background-color: rgb(42,52,62); border:0px;}");
          return button ;
      }
      
      QGraphicsDropShadowEffect *RamadanTimes::createShadow(QGraphicsDropShadowEffect *shadow,int x, int y, int radius, QString color){
      
          shadow = new QGraphicsDropShadowEffect ;
          shadow->setXOffset(x);
          shadow->setYOffset(y);
          shadow->setBlurRadius(radius);
          shadow->setColor(color);
          return shadow ;
      }
      
      QFrame *RamadanTimes::constructFrame(QFrame *frame,QGraphicsDropShadowEffect *shadow){
      
          frame = new QFrame(this);
          frame->setGeometry(75,70,515,440);
          frame->setGraphicsEffect(shadow);
          return frame ;
      }
      
      
      E Offline
      E Offline
      Eeli K
      wrote on last edited by
      #2

      @Ahti It's probably a problem with your memory management. It looks to me like you have a pointer to a button as a member in RamadanTimes. Follow the values of that pointer variable and each *button variable with qDebug() << home and qDebug() << button statements in each function and you may find a problem.

      AhtiA 1 Reply Last reply
      1
      • E Eeli K

        @Ahti It's probably a problem with your memory management. It looks to me like you have a pointer to a button as a member in RamadanTimes. Follow the values of that pointer variable and each *button variable with qDebug() << home and qDebug() << button statements in each function and you may find a problem.

        AhtiA Offline
        AhtiA Offline
        Ahti
        wrote on last edited by
        #3

        @Eeli-K qDebug() << home ; displays "QWidget(0x0)" instead of an address of "home" pointer

        what is a signature ?? Lol

        E 1 Reply Last reply
        0
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by VRonin
          #4

          You pass the pointer by value, the button = assignment will not be reflected outside setupWidgets

          change RamadanTimes::setupWidgets(QToolButton *button,QGraphicsDropShadowEffect *panelshadow,QFrame *panel,int w,QString image) to RamadanTimes::setupWidgets(QToolButton*& button,QGraphicsDropShadowEffect*& panelshadow,QFrame*& panel,int w,const QString& image)

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          AhtiA 1 Reply Last reply
          8
          • AhtiA Ahti

            @Eeli-K qDebug() << home ; displays "QWidget(0x0)" instead of an address of "home" pointer

            E Offline
            E Offline
            Eeli K
            wrote on last edited by Eeli K
            #5

            @Ahti VRonin's solution is good if you want to do minimal changes. On the other hand you have strange architecture - why you pass the members as arguments at all to member functions? You could do

            void RamadanTimes::setupWidgets(int w,QString image){
            home = new QToolButton(menubar);
            home->setGeometry...
            // init the button...
            panelshadow = new...
            // init the shadow...
            panel = new...
            //init the frame
            
            AhtiA 1 Reply Last reply
            0
            • E Eeli K

              @Ahti VRonin's solution is good if you want to do minimal changes. On the other hand you have strange architecture - why you pass the members as arguments at all to member functions? You could do

              void RamadanTimes::setupWidgets(int w,QString image){
              home = new QToolButton(menubar);
              home->setGeometry...
              // init the button...
              panelshadow = new...
              // init the shadow...
              panel = new...
              //init the frame
              
              AhtiA Offline
              AhtiA Offline
              Ahti
              wrote on last edited by
              #6

              @Eeli-K Because i have more QWidgets not just one.

              what is a signature ?? Lol

              E 1 Reply Last reply
              0
              • VRoninV VRonin

                You pass the pointer by value, the button = assignment will not be reflected outside setupWidgets

                change RamadanTimes::setupWidgets(QToolButton *button,QGraphicsDropShadowEffect *panelshadow,QFrame *panel,int w,QString image) to RamadanTimes::setupWidgets(QToolButton*& button,QGraphicsDropShadowEffect*& panelshadow,QFrame*& panel,int w,const QString& image)

                AhtiA Offline
                AhtiA Offline
                Ahti
                wrote on last edited by
                #7

                @VRonin Thanks brother :D love you :)

                what is a signature ?? Lol

                1 Reply Last reply
                1
                • AhtiA Ahti

                  @Eeli-K Because i have more QWidgets not just one.

                  E Offline
                  E Offline
                  Eeli K
                  wrote on last edited by
                  #8

                  @Ahti I don't understand. What QWidgets you mean? If you have several RamadanTimes objects (which are QMainWindows) they each have their own buttons etc. The main point of objects (and classes) is to encapsulate data and behaviour into one object. The member data of each object can be accessed in member functions so that it doesn't have anything to do with other objects of the same class. Static members are class-wide, shared between objects of the same class. One just shouldn't pass normal data members as arguments to normal member functions because they can be accessed directly by the member functions.

                  AhtiA 1 Reply Last reply
                  0
                  • E Eeli K

                    @Ahti I don't understand. What QWidgets you mean? If you have several RamadanTimes objects (which are QMainWindows) they each have their own buttons etc. The main point of objects (and classes) is to encapsulate data and behaviour into one object. The member data of each object can be accessed in member functions so that it doesn't have anything to do with other objects of the same class. Static members are class-wide, shared between objects of the same class. One just shouldn't pass normal data members as arguments to normal member functions because they can be accessed directly by the member functions.

                    AhtiA Offline
                    AhtiA Offline
                    Ahti
                    wrote on last edited by
                    #9

                    @Eeli-K

                    this is what i mean brother:

                    setupWidgets(home,homepanelShadow,homepanel,50,":/Images/Home.png");
                    setupWidgets(settings,settingspanelShadow,settingspanel,150,":/Images/settings.png");
                    setupWidgets(contact,contactpanelShadow,contactpanel,250,":/Images/Contact.png");
                    setupWidgets(about,aboutpanelShadow,aboutpanel,350,":/Images/About.png");
                    

                    what is a signature ?? Lol

                    E 1 Reply Last reply
                    0
                    • AhtiA Ahti

                      @Eeli-K

                      this is what i mean brother:

                      setupWidgets(home,homepanelShadow,homepanel,50,":/Images/Home.png");
                      setupWidgets(settings,settingspanelShadow,settingspanel,150,":/Images/settings.png");
                      setupWidgets(contact,contactpanelShadow,contactpanel,250,":/Images/Contact.png");
                      setupWidgets(about,aboutpanelShadow,aboutpanel,350,":/Images/About.png");
                      
                      E Offline
                      E Offline
                      Eeli K
                      wrote on last edited by
                      #10

                      @Ahti OK, now I understand better. The case is closed.

                      1 Reply Last reply
                      1

                      • Login

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