Close and Delete QMainWindow and Confirm it Deleted
-
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 classIts 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 -
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? -
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();
}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
-
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();
-
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.