Results 1 to 3 of 3

Thread: Event handling problem

  1. #1
    Join Date
    Aug 2007
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Event handling problem

    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:

    Qt Code:
    1. #include <qapplication.h>
    2. #include <qfontdatabase.h>
    3. #include "main_widget.h"
    4. #include "app.xpm"
    5.  
    6. //int DDS::loLcdValue=0;
    7.  
    8. int main (int argc, char **argv)
    9. {
    10. QApplication app(argc, argv);
    11. Main_Widget *w = new Main_Widget;;
    12. app.setWindowIcon( QIcon(app_xpm) );
    13. app.setStyleSheet("QFrame {border : 1px solid rgb(255,200,55)}");
    14. w->show();
    15. return app.exec();
    16. }
    17.  
    18. #include "main_widget.h"
    19.  
    20. Main_Widget::Main_Widget(QWidget *parent)
    21. : QWidget(parent)
    22. {
    23. setDds( 5 );
    24. }
    25.  
    26. void Main_Widget::closeEvent( QCloseEvent * )
    27. {
    28. printf("Main_Widget::closeEvent\n");
    29. finish();
    30. }
    31.  
    32. void Main_Widget::finish()
    33. {
    34. // saveSettings();
    35. exit( 0 );
    36. }
    37.  
    38. void Main_Widget::setDds( int )
    39. {
    40. SDR_ShellDDS = new DDS;
    41. }
    42.  
    43.  
    44. #ifndef SDXCVR_MAINWIDGET_H
    45. #define SDXCVR_MAINWIDGET_H
    46.  
    47. #include <qwidget.h>
    48. #include <qapplication.h>
    49.  
    50. #include "DDS.h"
    51.  
    52. class Main_Widget : public QWidget
    53. {
    54.  
    55.  
    56. Q_OBJECT
    57.  
    58. private:
    59. DDS *SDR_ShellDDS;
    60.  
    61. public:
    62. Main_Widget(QWidget *parent = 0);
    63.  
    64. public slots:
    65. void finish();
    66. void setDds( int );
    67.  
    68. protected:
    69. void closeEvent( QCloseEvent * );
    70.  
    71. };
    72. #endif
    73.  
    74.  
    75. #include "DDS.h"
    76.  
    77. DDS::DDS( QWidget *parent)
    78. : QWidget( parent)
    79. {
    80.  
    81. ddsFrame = new QFrame();
    82. ddsFrame->setGeometry( 400, 200, 450, 300 );
    83. ddsFrame->setMinimumWidth( 450 );
    84. ddsFrame->setMinimumHeight( 300 );
    85. ddsFrame->setWindowTitle("SDR-Shell : Frequency Control ");
    86.  
    87. ddsFrame->show();
    88.  
    89. }
    90.  
    91. void DDS::closeEvent( QCloseEvent *e )
    92. {
    93. printf("closeEvent( QCloseEvent * )\n");
    94. e->accept();
    95. finish();
    96. }
    97.  
    98. void DDS::finish()
    99. {
    100. printf("finish()\n");
    101. // exit( 0 );
    102. }
    103.  
    104.  
    105. #ifndef DDS_H
    106. #define DDS_H
    107.  
    108. #include <QWidget>
    109. #include <QFrame>
    110. #include <QCloseEvent>
    111. #include <QEvent>
    112. #include <QAction>
    113. #include <QObject>
    114.  
    115.  
    116. class DDS : public QWidget
    117. {
    118. Q_OBJECT
    119.  
    120.  
    121. private:
    122.  
    123. QFrame *ddsFrame;
    124.  
    125. public:
    126.  
    127. DDS(QWidget *parent = 0);
    128.  
    129. private slots:
    130.  
    131. void finish();
    132.  
    133. protected:
    134. void closeEvent( QCloseEvent * );
    135.  
    136. };
    137. #endif
    To copy to clipboard, switch view to plain text mode 
    Last edited by jacek; 22nd August 2007 at 22:51. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Event handling problem

    The problem is that you never show that DDS widget, only ddsFrame, so DDS doesn't receive any close events.

  3. #3
    Join Date
    Aug 2007
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Event handling problem

    Jacek,

    Thanks for the reply. Yep, that was indeed the problem. I knew it had to be something fundamental. I'm still learning about C++ and Qt, and the forum has been a big help.

    Thanks again for your response.


    Mel Seyle

Similar Threads

  1. QGraphicsView Handling Child Event
    By arjunasd in forum Qt Programming
    Replies: 1
    Last Post: 9th August 2007, 00:32
  2. Problem with qtoolbutton
    By moowy in forum Qt Programming
    Replies: 1
    Last Post: 22nd September 2006, 13:30
  3. event problem
    By windkracht8 in forum Qt Programming
    Replies: 5
    Last Post: 17th August 2006, 11:52
  4. Workload in a QThread blocks main application's event loop ?
    By 0xBulbizarre in forum Qt Programming
    Replies: 14
    Last Post: 9th April 2006, 21:55
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.