I'm trying to get an object to handle a QCloseEvent. The object, DDS, is instantiated in Main_Widget, and pops up as a smaller window. In this case all the close event in the new DDS object is supposed to do is execute a printf that shows that closeEvent was indeed called. However, when the DDS object is closed, it appears that closeEvent is never called. Note that a similar closeEvent in Main_Widget will execute its printf, and the desired message appears.
I'm missing something fundamental here, but haven't been able to track it down.
Thanks.
Mel Seyle
code follows:
#include <qapplication.h>
#include <qfontdatabase.h>
#include "main_widget.h"
#include "app.xpm"
//int DDS::loLcdValue=0;
int main (int argc, char **argv)
{
Main_Widget *w = new Main_Widget;;
app.
setWindowIcon( QIcon(app_xpm
) );
app.setStyleSheet("QFrame {border : 1px solid rgb(255,200,55)}");
w->show();
return app.exec();
}
#include "main_widget.h"
Main_Widget
::Main_Widget(QWidget *parent
){
setDds( 5 );
}
{
printf("Main_Widget::closeEvent\n");
finish();
}
void Main_Widget::finish()
{
// saveSettings();
exit( 0 );
}
void Main_Widget::setDds( int )
{
SDR_ShellDDS = new DDS;
}
#ifndef SDXCVR_MAINWIDGET_H
#define SDXCVR_MAINWIDGET_H
#include <qwidget.h>
#include <qapplication.h>
#include "DDS.h"
{
Q_OBJECT
private:
DDS *SDR_ShellDDS;
public:
public slots:
void finish();
void setDds( int );
protected:
};
#endif
#include "DDS.h"
{
ddsFrame->setGeometry( 400, 200, 450, 300 );
ddsFrame->setMinimumWidth( 450 );
ddsFrame->setMinimumHeight( 300 );
ddsFrame->setWindowTitle("SDR-Shell : Frequency Control ");
ddsFrame->show();
}
{
printf("closeEvent( QCloseEvent * )\n");
e->accept();
finish();
}
void DDS::finish()
{
printf("finish()\n");
// exit( 0 );
}
#ifndef DDS_H
#define DDS_H
#include <QWidget>
#include <QFrame>
#include <QCloseEvent>
#include <QEvent>
#include <QAction>
#include <QObject>
{
Q_OBJECT
private:
public:
private slots:
void finish();
protected:
};
#endif
#include <qapplication.h>
#include <qfontdatabase.h>
#include "main_widget.h"
#include "app.xpm"
//int DDS::loLcdValue=0;
int main (int argc, char **argv)
{
QApplication app(argc, argv);
Main_Widget *w = new Main_Widget;;
app.setWindowIcon( QIcon(app_xpm) );
app.setStyleSheet("QFrame {border : 1px solid rgb(255,200,55)}");
w->show();
return app.exec();
}
#include "main_widget.h"
Main_Widget::Main_Widget(QWidget *parent)
: QWidget(parent)
{
setDds( 5 );
}
void Main_Widget::closeEvent( QCloseEvent * )
{
printf("Main_Widget::closeEvent\n");
finish();
}
void Main_Widget::finish()
{
// saveSettings();
exit( 0 );
}
void Main_Widget::setDds( int )
{
SDR_ShellDDS = new DDS;
}
#ifndef SDXCVR_MAINWIDGET_H
#define SDXCVR_MAINWIDGET_H
#include <qwidget.h>
#include <qapplication.h>
#include "DDS.h"
class Main_Widget : public QWidget
{
Q_OBJECT
private:
DDS *SDR_ShellDDS;
public:
Main_Widget(QWidget *parent = 0);
public slots:
void finish();
void setDds( int );
protected:
void closeEvent( QCloseEvent * );
};
#endif
#include "DDS.h"
DDS::DDS( QWidget *parent)
: QWidget( parent)
{
ddsFrame = new QFrame();
ddsFrame->setGeometry( 400, 200, 450, 300 );
ddsFrame->setMinimumWidth( 450 );
ddsFrame->setMinimumHeight( 300 );
ddsFrame->setWindowTitle("SDR-Shell : Frequency Control ");
ddsFrame->show();
}
void DDS::closeEvent( QCloseEvent *e )
{
printf("closeEvent( QCloseEvent * )\n");
e->accept();
finish();
}
void DDS::finish()
{
printf("finish()\n");
// exit( 0 );
}
#ifndef DDS_H
#define DDS_H
#include <QWidget>
#include <QFrame>
#include <QCloseEvent>
#include <QEvent>
#include <QAction>
#include <QObject>
class DDS : public QWidget
{
Q_OBJECT
private:
QFrame *ddsFrame;
public:
DDS(QWidget *parent = 0);
private slots:
void finish();
protected:
void closeEvent( QCloseEvent * );
};
#endif
To copy to clipboard, switch view to plain text mode
Bookmarks