PDA

View Full Version : can i provide delay between two lines without using timer function?



athulms
25th August 2011, 12:43
code1
code2
code3

i want to execute code 3 after 1sec delay from code2 execution.
Without timer can i do it??
I am using paintevent which is automatically called 10times/sec.

high_flyer
25th August 2011, 12:45
why not using QTimter?
Sounds like a design problem.
If you give more details on the scenario, we probably can help you find a better solution.

athulms
26th August 2011, 05:09
i am developing a wordsearch game. when i selects a correct word a line should be drawn upon the selected word. if my selection is wrong the line drawn should be cleared after 200ms. I have started a timer after drawing the line in case of wrong selection and on timer time out i used
painter->eraseRect(100,40,550,440); but it does not works in a timer. it shows a visual studio runtime error. I guess its because the paint event is called continously.

Now i used the code write next to the line drawing. so i cant see the line for 200ms. but the same
painter->eraseRect(100,40,550,440); shows no error when its used next with the drawline code

high_flyer
26th August 2011, 09:21
but it does not works in a timer. it shows a visual studio runtime error. I guess its because the paint event is called continously.
show your code.

wysota
26th August 2011, 11:04
Your design is totally wrong, I'm afraid. You are thinking in a synchronous way but using an asynchronous environment. And your painting is totally wrong as already stated in the other thread of yours. paintEvent is meant to paint the current state on a clear (erased) canvas. After 200ms state of your widget should change and that should trigger a repaint and not the other way round. You can't "update" the current painting, you need to redraw from the beginning.

DanH
27th August 2011, 03:09
Sorry, in an application that uses the GUI interfaces you should not (and in many cases MUST not) insert delay operations inline in your code. You need to learn how to think about things a bits of separate but interdependent code that are each triggered by events of some sort.