[Qt-interest] Resolved...Re: processEvents() and reset.

phil prentice philp.cheer at talktalk.net
Sun Oct 31 17:03:27 CET 2010


Hi

  Just to say that I (think I)have done what Andreas recommended and its fixed 
my problem.  I created a new thread that emited signals to the parent. These 
signals updated some of the widgets of the parent(dialog) as it was looping 
around the networks.  I also called a member function of the parent inside 
the same loop to check the m_reset variable (set by the user selecting a 
button connected to a slot that modified the m_reset variable). This then 
enabled me to abort on a reset. It works fine...

  It took me a while to write the new code for the thread and interacttion 
(including the passing of several parameters from the dialog to the thread).
  What I had before was much simpler, but did'nt always work. This method 
does, I'm afraid also that maybe I was just being lazy!!!

Thanks for your help

Phil

On Friday 29 October 2010 20:10, phil prentice wrote:
> Hi Andreas
>  Thankyou for your help.
>
>   My application kicks the dialog off as a modal dialog box. So the only
> means of getting input to the application is through the modal dialog box.
> I'm not aware of any code in my app that gets executed just by moving the
> mouse into it....unless it is something to do with focus??!!!
>
>   Ok, what my code is trying to do is to talk to some hardware to learn
> some signal data (one network at a time).  There might be up to 10,000
> networks. When the run pushbutton is pushed the slot loops on the networks,
> one at a time and calls an external library function to perform the learn
> for that network.  This works well.  After processing each network in the
> loop the code inside the loop checks a member variable called m_reset.  The
> reset slot invoked from the reset pushbutton sets m_reset to enable the
> loop to be aborted.
>
>   Are you saying that what I should be doing here is to start a thread off
> doing the 10000 or so nets, but the thread would monitor a member variable
> of the dialog. How best should I do this?  Pass the member variable in as
> an address?  Access it via the dialogs parent pointer or can I use
> signal/slots somehow. Which method do you recommend??  Hopefully this
> should then fix this focus problem???
>
>   Thankyou very much for your advice
>
> Phil
>
> On Friday 29 October 2010 17:16, Andreas Pakulat wrote:
> > On 29.10.10 16:27:32, phil prentice wrote:
> > >   I have a simple dialog. When you click a button on the dialog a slot
> > > is called that loops around some code performing an action.  I have
> > > another slot that gets called when another button(reset) is pressed on
> > > the same dialog.  I use processEvents() within the loop to catch the
> > > reset button being pressed. This works absolutely fine if I leave the
> > > mouse inside of the dialog.  I can start the loop and reset the loop
> > > with no problems. Its lovely and simple!!!
> > >
> > >   Unfortunately I have a problem; if I move the mouse outside of the
> > > dialog and back in...the reset button no longer responds quite so well.
> > > I presume that its got something to do with the focus changing???  But
> > > reset is certainly not quick then...in fact sometimes I cant get it to
> > > work at all.
> > >
> > >   Is there a quick fix for this?
> >
> > Without seeing some code my suggestion is to check for any code that can
> > be executed when events are being fired. With your processEvents calling
> > you're processing all events in your application. So any code that
> > handles events can be executed while you're in your loop. So there might
> > be code in your app that gets executed which you don't expect to be on a
> > first look.
> >
> > Its not quite clear why you're calling processEvents, options to avoid
> > it are splitting up the work into smaller/shorter pieces and executing
> > them in steps with a timer for example. Or move the logic into a
> > separate thread so that the normal event loop can continue.
> >
> > Andreas
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest



More information about the Qt-interest-old mailing list