Results 1 to 7 of 7

Thread: design pattern for long time operation

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2008
    Location
    Poland
    Posts
    383
    Thanks
    52
    Thanked 42 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Android

    Default design pattern for long time operation

    Hello.
    I don't know if this is right place to write this, so pardon me if it's not.
    Problem: perform many operation (like 12k++) one after another (to shorten this time I want to execute each operation as soon as previouse is finished). So in nutshell the same set of functions are performed many times on different set of data.

    My implementation:
    Currently I do it "wrong way" and not so wrong (maybe a right?) way.

    Wrong way using signal/slot mechanism (wrong in terms of logical implementation, not in code itself) - pseudo code:

    Qt Code:
    1. void myProgrma::myProgrma(){
    2. connect( this, SIGNAL( jobDone() ), this, SLOT(controlSLOT()));
    3. myProgrma();
    4. }
    5. void myProgrma::controlSLOT()
    6. {
    7. if(jobIsDone)
    8. return;
    9. else
    10. doJobSLOT()
    11. }
    12.  
    13. void myProgrma::doJobSLOT()
    14. {
    15. //do job here
    16. emit jobDone();
    17. }
    To copy to clipboard, switch view to plain text mode 
    As you can see there is one flaw with this implementation with is that for many, like 64k++, jobs (or less depending on what is in doJobSLOT() ) this will fail (AFAIK - please elaborate about this, if my thinking is wrong) due to the exceeding job queue stack size - due to not returning from slots that's leads to queue being full and thus error.

    I found out, on my trails and errors path, that using only signal/slot mechanism is a loot more faster then using QTimer solution (QTimer is about 6+ times slower). I guess that's due to the all those checks and overhead of the QTimer class. Basically I'm looking for fastest i9mplementation of this problem.

    I know that I can implement solution for this problem using QTimer and timeout() signal, but my question is:
    Is there any other way to implement "while/for" loop behaviour (basically above example does those loops) (or AFAIK so called Observer Pattern) in Qt?

    Thank you for any advice on this mater.
    Best regards.

    PS. in pseudo code "jobIsDone" is bool to check if there is any pending job to be done.
    Last edited by Talei; 21st July 2011 at 22:44. Reason: updated contents
    In the near future - corporate networks reach out to the stars. Electrons and light flow throughout the universe.
    The advance of computerization however, has not yet wiped out nations and ethnic groups.

Similar Threads

  1. Long operation -> Refresh user interface
    By pl01 in forum Qt Programming
    Replies: 2
    Last Post: 31st January 2011, 10:23
  2. design pattern for supporting multiple DB's?
    By scarleton in forum Qt Programming
    Replies: 3
    Last Post: 4th June 2010, 14:33
  3. Design pattern of qwt library
    By Hogwarts in forum Qwt
    Replies: 1
    Last Post: 4th June 2010, 10:04
  4. GIS design pattern
    By olosie in forum Qt Programming
    Replies: 2
    Last Post: 19th May 2009, 16:19
  5. Observer Design Pattern
    By joseph in forum General Programming
    Replies: 1
    Last Post: 21st January 2008, 12:17

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
  •  
Qt is a trademark of The Qt Company.