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. Close and Delete QMainWindow and Confirm it Deleted

Close and Delete QMainWindow and Confirm it Deleted

Scheduled Pinned Locked Moved General and Desktop
5 Posts 4 Posters 3.9k 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
    praveen0991kr
    wrote on last edited by
    #1

    Dear All ,
    I have written an application where for every class I have own set of variable and function and To move to new class I have to close previous class object and creating new controuctor for the class I am going to open ;

    A class (closing A class Variable Opening B Class) --> B Class
    B Class (closing B class Variable Opening C Class )--> C class
    A class (closing A class Variable Opening M Class) --> M Class
    A class (closing A class Variable Opening N Class) --> N Class


    M class (closing M class Variable Opening A Class) --> A Class
    N Class (closing N class Variable Opening A Class )--> A class

    Its a random sequence ;
    for closing class I am performing the same
    @
    QTimInvStatus->stop();
    QTimInvStatus->deleteLater();
    UpdatScr->stop();
    UpdatScr->deleteLater();
    myPTransitn->stop();
    myPTransitn->deleteLater();
    homescr::close();

    and Before that I am openning new class

    myActvAlrm = new ActiveAlarms();
    myActvAlrm->showFullScreen();
    myActvAlrm->show();
    

    @

    but It that I am not able to be so sure the object are deleted ;

    and what I found Some times I saw Segmentation Fault :error 139 that I found on searching that it is acess the pionter; which either out of application range and returning 0 and result it crashes ;

    Pls help at what point I am lagging ;

    Regards
    Praveen Kumar

    1 Reply Last reply
    0
    • JeroentjehomeJ Offline
      JeroentjehomeJ Offline
      Jeroentjehome
      wrote on last edited by
      #2

      Hi,
      What type of classes are you copying? Do take into consideration that a copy of a QObject is NOT possible.
      Your code is a bit slim. How and where do you create and delete the classes?

      Greetz, Jeroen

      1 Reply Last reply
      0
      • P Offline
        P Offline
        praveen0991kr
        wrote on last edited by
        #3

        Hi,
        Thanks for Reply !

        QMainwindow (GUI)
        @
        Main.c
        #include <QtGui/QApplication>
        #include "homescreen.h"

        int main(int argc, char *argv[])
        {
        QApplication a(argc, argv);
        Homescreen w;
        w.showFullScreen();
        return a.exec();
        }

        //homescreen.c

        homescr::homescr(QWidget *parent) : QDialog(parent),
        ui(new Ui::homescr)
        {
        ui->setupUi(this); qDebug()<<"homeScr";

        //*QTIMER INITIALIZATION
        UpdatScr = new QTimer(this);
        UpdatScr->start(500);

        connect(UpdatScr,SIGNAL(timeout()),this,SLOT(UpdateScreen()));
        connect(ui->Meter,SIGNAL(clicked()),this,SLOT(Meter()));
        }
        homescr::~homescr()
        {
        delete ui;

        }
        void homescr::Meter()
        {

        myMeterScr_1 = new Meter();
        myMeterScr_1->showFullScreen();
        myMeterScr_1->show();
        UpdatScr->stop();
        UpdatScr->deleteLater();
        homescr::close();
        

        }
        void homescr::UpdateScreen()
        {
        X();
        Y();
        Z();
        }
        void homescr::X()
        {
        GWin->RTClock(); //Access function from other class
        QPalette sample_palette;
        sample_palette.setColor(QPalette::Window, Qt::white);
        sample_palette.setColor(QPalette::WindowText, Qt::blue);
        ui->Date_Lable->setAutoFillBackground(true);
        ui->Date_Lable->setPalette(sample_palette);

        ui->TimeLable->setAutoFillBackground(true);
        ui->TimeLable->setPalette(sample_palette);
        ui->Date_Lable->setText(Dat);
        ui->TimeLable->setText(Tim);
        

        }
        void homescr::Y(){
        }
        void homescr::Z(){
        }

        @
        Pls do suggest is any thind gone wrong !!

        Praveen

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          Your design makes me think of something like a strange wizard. Also myMeterScr_1 is leaking, you don't delete it anywhere.

          UpdatScr should rather be a single shot since it seems it's fired only once.

          homescr::close(); is a call to a static function, you should just call close();

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • dheerendraD Offline
            dheerendraD Offline
            dheerendra
            Qt Champions 2022
            wrote on last edited by
            #5

            As SGaist said, your overall flow,object creation and deletion will surely mess up things. My suggestion is to re-think on over-all handling of your flow and object creation. Current flow has memory leaks, objects are closed unnecessarily.

            Happy for re-design.

            Dheerendra
            @Community Service
            Certified Qt Specialist
            http://www.pthinks.com

            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