Results 1 to 4 of 4

Thread: MessageLoop in DropDownColorPicker causes crash when parents get closed

  1. #1
    Join Date
    Feb 2013
    Posts
    4
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default MessageLoop in DropDownColorPicker causes crash when parents get closed

    Hello,

    I'm trying to write me a color picker widget. The idea is, that it folds up from a smaller 'Select Color'-Button, and disappears if the user clickes anything else than the picker widget. So the widget is non-modal. (Think it similar to a drop down listbox.) Additional I would like to keep the applications UI responsive while the user is picking the color, to update the preview in the main view and - this is where the problem comes in - and to do this via an exec()-function containing a message loop (like the QFileDialog).
    Qt Code:
    1. bool DropDownColorPickerWidget::exec()
    2. {
    3. m_result = true;
    4. show();
    5. QEventLoop eventLoop( this );
    6. eventLoop.processEvents();
    7.  
    8. activateWindow();
    9. while( isVisible() )
    10. eventLoop.processEvents();
    11.  
    12. return m_result;
    13. }
    To copy to clipboard, switch view to plain text mode 
    In general this seems to work, but when parent-widget of the picker widget is closed while the application is inside the pickers message loop this causes a crash.
    So I´m looking for a possiblity for either preventing the parent widgets (and the application) from closing while the picker is poped up or for a way to exit the message loop before the deletion of the parent objects takes place.

    Thanks in advance for any hints or advice.

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: MessageLoop in DropDownColorPicker causes crash when parents get closed

    Try this (I have not tried this), but will be interested to know the results.
    1. Implement/filter QWidget::closeEvent(), (of the parent window)
    2. Hide the widget
    3. Reject the event, i.e event->ignore()/return false;
    4. deleteLater() the widget
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

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

    j.mueller (11th February 2013)

  4. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: MessageLoop in DropDownColorPicker causes crash when parents get closed

    Nested event loops are usually a very bad idea and should only be used when really, really necessary and under full understanding what they do.

    In your case you seem to not need it for any filtering, in fact you write that you want it to be have non-modal.
    Why not just use the normal event processing and asynchronously return the result via signal?

    Cheers,
    _

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

    j.mueller (11th February 2013)

  6. #4
    Join Date
    Feb 2013
    Posts
    4
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: MessageLoop in DropDownColorPicker causes crash when parents get closed

    Thanks a lot for your help.
    I already tried the suggestions of Mr. Reddy. Although I also thought any of this approaches should do the job, nothing of it worked for me. But maybe I just implemented it in the right way.
    So I think I´m now switching the widget to a more signal-slot based design.

Similar Threads

  1. Multiple parents; not inheritance
    By tescrin in forum Qt Programming
    Replies: 15
    Last Post: 13th August 2012, 21:46
  2. Layout parents
    By qtnewbie500 in forum Newbie
    Replies: 1
    Last Post: 6th April 2012, 04:07
  3. How to access parents variables
    By revellix in forum Qt Programming
    Replies: 3
    Last Post: 10th October 2011, 15:03
  4. Semi-transparency through parents' widgets
    By Anatoly in forum Qt Programming
    Replies: 2
    Last Post: 21st December 2009, 09:23
  5. QStandardItemModel, parents and childs
    By alexandernst in forum Newbie
    Replies: 7
    Last Post: 23rd July 2009, 00:00

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.