Results 1 to 1 of 1

Thread: synchronizing events

  1. #1
    Join Date
    Jun 2006
    Posts
    81
    Thanks
    6
    Thanked 5 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Question synchronizing events

    Hi all,

    This is in a way the follow-up to this thread. Please consider the code fragment in the starting post thereabout. There are some minor changes, and MyWrapper inherits QAbstractScrollArea now, but basically it's the same.

    My problem is: I can't make MyWrapper paint on its viewport() properly due to synchronization problems with Foo::update().

    These are the facts:
    • All painting has to take place within MyWrapper::paintEvent().
    • All rendering is triggered by calling (3rd-party class method) Foo::update(). This starts a thread which I have no access to.
    • Hooks (callbacks) can be registered with Foo that are then called to indicate start/finish of the rendering. As these then belong to render thread, they cannot repaint MyWrapper directly. Instead they need to go via main event loop by calling MyWrapper::update() or posting a custom event.
    • In MyWrapper::paintEvent() handler, depending on event origin and Foo's state, either the rendering must be triggered, or the results painted. Mind that before paintEvent() is entered the widget is usually erased by Qt.
    • Whichever way of signalling from within the hook is used: Eventually a paint event need be sent. This may interfere with paint events sent by the window system and is where the synchronization problem arises.

    So, as I currently see it, the problem is basically to distinguish between paint events that originate from Foo::hook() and those that don't.

    I thought of subclassing QPaintEvent, but as events do not inherit QObject, there is no way of identifying these custom paint events within MyWrapper::paintEvent().
    As wysota advised in the other thread, I do manage a QImage class variable MyWrapper::_img that is initialized by a custom event handler from the finish hook, and uninitialized from the start hook. However, this alone does not suffice as the hooks need to signal via the main event loop and thus asynchronously, leaving the state of _img somewhat uncertain.

    I tried a gazillion things, so I may well not see the wood for the trees anymore. Is there an obvious solution after all? Any help appreciated very much.
    Last edited by zaphod.b; 14th July 2009 at 17:07.

Similar Threads

  1. QGraphicsView Mouse Events
    By tomf in forum Qt Programming
    Replies: 5
    Last Post: 29th July 2008, 15:03
  2. Replies: 9
    Last Post: 22nd June 2008, 22:26
  3. Replies: 1
    Last Post: 21st August 2007, 16:25
  4. How to suppress user defined events in processEvents()
    By Artschi in forum Qt Programming
    Replies: 5
    Last Post: 5th July 2007, 10:17
  5. QStackerWidget and mouse events
    By high_flyer in forum Qt Programming
    Replies: 3
    Last Post: 25th April 2006, 19:25

Tags for this Thread

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.