Results 1 to 6 of 6

Thread: event problem

  1. #1
    Join Date
    Aug 2006
    Posts
    27
    Thanks
    2
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default event problem

    Hello all,

    strange thing I'm seeing in this code.
    Somehow I have to catch the "QEvent::Close" event and call "qApp->quit()" . Otherwise the program won't close!

    Anyone any idea how this is possible? It does call the event close, it want's to close, I ignore the event but nothing happens.

    Cheers,
    Bart.


    Qt Code:
    1. bool frmMain::event(QEvent* event)
    2. {
    3. if(event->type() == QEvent::User){
    4. bC* eTemp = (bC*)event;
    5. iTemp = eTemp->rij();
    6. iTemp2 = eTemp->col();
    7. knopGeklikt(iTemp,iTemp2);
    8. event->accept();
    9. return true;
    10. }
    11. //this part is needed somehow
    12. if(event->type() == QEvent::Close){
    13. qApp->quit();
    14. event->accept();
    15. return true;
    16. }
    17. //up till here
    18.  
    19. event->ignore();
    20. return false;
    21. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: event problem

    It is not recommended to reimplement the main event handler. Use specialized event handlers instead. Eg. closeEvent() for QEvent::Close type and customEvent() for type values starting from QEvent::User and so on.

    Your form might not work very well because you are ignoring a bunch of events. QWidget base class implementation (which you have overridden with your own implementation) does a lot of handling based on the event type and later calls the specialized event handler (which is the one supposed to be overridden..)

    So start with moving the block of code handling QEvent::User types to customEvent() and forget about overriding event()..
    J-P Nurmi

  3. The following user says thank you to jpn for this useful post:

    windkracht8 (17th August 2006)

  4. #3
    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 problem

    Quote Originally Posted by windkracht8
    Anyone any idea how this is possible?
    You don't invoke the base class implementation.

    Try:
    Qt Code:
    1. bool frmMain::event(QEvent* event)
    2. {
    3. if(event->type() == QEvent::User){
    4. bC* eTemp = (bC*)event;
    5. iTemp = eTemp->rij();
    6. iTemp2 = eTemp->col();
    7. knopGeklikt(iTemp,iTemp2);
    8. event->accept();
    9. return true;
    10. }
    11. return QWidget::event( event );
    12. }
    To copy to clipboard, switch view to plain text mode 
    or better:
    Qt Code:
    1. bool frmMain::customEvent(QEvent* event)
    2. {
    3. if(event->type() == QEvent::User){
    4. bC* eTemp = (bC*)event;
    5. iTemp = eTemp->rij();
    6. iTemp2 = eTemp->col();
    7. knopGeklikt(iTemp,iTemp2);
    8. event->accept();
    9. return true;
    10. }
    11. return QWidget::customEvent( event );
    12. }
    To copy to clipboard, switch view to plain text mode 

  5. The following user says thank you to jacek for this useful post:

    windkracht8 (17th August 2006)

  6. #4
    Join Date
    Aug 2006
    Posts
    27
    Thanks
    2
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: event problem

    Qt is getting a little more clear now. Thanks for the respons.
    One more question though:

    This piece of code:
    Qt Code:
    1. bool frmMain::customEvent(QEvent* event)
    2. {
    3. if(event->type() == QEvent::User){
    4. bC* eTemp = (bC*)event;
    5. iTemp = eTemp->rij();
    6. iTemp2 = eTemp->col();
    7. knopGeklikt(iTemp,iTemp2);
    8. event->accept();
    9. return true;
    10. }
    11. return QWidget::customEvent( event );
    12. }
    To copy to clipboard, switch view to plain text mode 
    Gave the error that "virtual bool QObject::customEvent(QEvent* event)" was overwriting
    "virtual void QObject::customEvent(QEvent* event)".
    So I'm going with this at the moment:
    Qt Code:
    1. void frmMain::customEvent(QEvent* event)
    2. {
    3. bC* eTemp = (bC*)event;
    4. iTemp = eTemp->rij();
    5. iTemp2 = eTemp->col();
    6. knopGeklikt(iTemp,iTemp2);
    7. event->accept();
    8. }
    To copy to clipboard, switch view to plain text mode 
    Should be ok right?
    I removed the "if(event->type() == QEvent::User)" statement becauss it looks obsolete, since customEvent doesn't get anything else then the "QEvent::User" and I only use one customevent.

    Thanks all,
    Bart.

  7. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: event problem

    Quote Originally Posted by windkracht8
    Should be ok right?
    I removed the "if(event->type() == QEvent::User)" statement becauss it looks obsolete, since customEvent doesn't get anything else then the "QEvent::User" and I only use one customevent.
    Yep, then looks fine.
    J-P Nurmi

  8. #6
    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 problem

    Quote Originally Posted by windkracht8
    Gave the error that "virtual bool QObject::customEvent(QEvent* event)" was overwriting
    "virtual void QObject::customEvent(QEvent* event)".
    I don't know where I saw that bool

Similar Threads

  1. Grid Layout Problem
    By Seema Rao in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2006, 12:45
  2. Problem with receiving events from QDateEdit
    By gunhelstr in forum Qt Programming
    Replies: 4
    Last Post: 20th April 2006, 11:21
  3. 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
  4. Problem with bitBlt
    By yellowmat in forum Newbie
    Replies: 1
    Last Post: 5th April 2006, 14:08
  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.