Results 1 to 6 of 6

Thread: can i provide delay between two lines without using timer function?

  1. #1
    Join Date
    Jul 2011
    Posts
    81
    Thanks
    8
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows Symbian S60 Maemo/MeeGo

    Default can i provide delay between two lines without using timer function?

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: can i provide delay between two lines without using timer function?

    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.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Jul 2011
    Posts
    81
    Thanks
    8
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows Symbian S60 Maemo/MeeGo

    Default Re: can i provide delay between two lines without using timer function?

    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
    Qt Code:
    1. painter->eraseRect(100,40,550,440);
    To copy to clipboard, switch view to plain text mode 
    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
    Qt Code:
    1. painter->eraseRect(100,40,550,440);
    To copy to clipboard, switch view to plain text mode 
    shows no error when its used next with the drawline code

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: can i provide delay between two lines without using timer function?

    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.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: can i provide delay between two lines without using timer function?

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Apr 2011
    Posts
    124
    Thanks
    1
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows Symbian S60

    Default Re: can i provide delay between two lines without using timer function?

    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.

Similar Threads

  1. Replies: 3
    Last Post: 24th April 2011, 16:35
  2. timer problem(timer does not work)
    By masuk in forum Newbie
    Replies: 6
    Last Post: 14th February 2011, 05:00
  3. How to add timer delay
    By qtUse in forum Newbie
    Replies: 1
    Last Post: 12th October 2010, 18:09
  4. Timer delay
    By bmn in forum Qt Programming
    Replies: 11
    Last Post: 3rd June 2008, 11:54
  5. How can i delay a function?
    By firenet in forum Qt Programming
    Replies: 2
    Last Post: 24th January 2007, 03:58

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.