Page 1 of 2 12 LastLast
Results 1 to 20 of 21

Thread: processEvents() and threads

  1. #1
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default processEvents() and threads

    Hi,

    when we call processEvents(), is there any way to specify which thread's events it should process????

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

    Default Re: processEvents() and threads

    As the docs say:
    Calling this function processes events only for the calling thread.
    And don't even think about anything different as it would make sense.

  3. #3
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: processEvents() and threads

    well, i read the docs and i read that..i was just clinging to a hope that it might be possible with maybe sm other function...

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

    Default Re: processEvents() and threads

    What do you need it for?

  5. #5
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: processEvents() and threads

    the problem is that i m showing a splashscreen for my application and on that i m showing a loading icon(gif image loaded by QMovie)..after i show the splashscreen and start the movie, there is a lot of heavy processing going on in ONE function which consumes a lot of time..due to which the loading icon doesnt animate at all..the first thing i tried was put processEvents() around that function, but to no avail..next i went inside the function and put a lot of processEvents() here and there in the function..which made the icon animate intermittently but still not smoothly..

    also, i m not allowed to make any changes in that function..so next i tried using a timer in the main() and call processEvents() through a slot to timeout(), but strangely that slot was called only one time until all the heavy processing was done..

    then i tried calling processEvents() from a different thread, not knowing that it processes events of the current thread o nly..that didntwork either(of course)..thats why i was wondering if processEvents() or any other function can process events of a different thread..i really need to be able to solve this problem somehow..and searching all thru different apis in QT, i couldnt find an answer..do u have any possible solution to it?

    thanks in advance!

  6. #6
    Join Date
    Dec 2007
    Posts
    40
    Thanks
    6
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: processEvents() and threads

    hi correct me if i am wrong, but i understand that your problem is:

    int main(void)
    {
    QApplication app;
    //animation code
    heavyProcessingFunc();
    app.exec();
    }

    calling processEvents() with a timer started in main also does not give timer call back.
    the timer of qt also works with the eventloop so till you do an app.exec() the event loop is not started and hence you wont get timercall backs.
    if you are not allowed to change the heayProcessingFunc() you should definitely move it into another thread. or else i dont think we can figure out a way to do the animation smoothly!!!
    but then the problem in interesting and a neat final solution would be a nice thing to see...

    cheers!
    Let your work talk for you

  7. #7
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: processEvents() and threads

    well, i cant move the heavy processing code to another thread cuz there are lots of gui calls in it..and a thread cant have gui calls..i think this problem can only be solved if i get to process events of main thread from another thread..for which i couldnt find an api..any other pointers?

  8. #8
    Join Date
    Dec 2007
    Posts
    40
    Thanks
    6
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: processEvents() and threads

    Quote Originally Posted by talk2amulya View Post
    well, i cant move the heavy processing code to another thread cuz there are lots of gui calls in it..and a thread cant have gui calls..i think this problem can only be solved if i get to process events of main thread from another thread..for which i couldnt find an api..any other pointers?
    does this heavy processing function call the GUI elements directly? would it not be possible to, in some way, decouple the function and the GUI elements?
    because, if it is not the case, we have a simple issue of a function which takes a lot of time being invoked in a thread! and obviously the thread does nothing but execute the function for a long time!!!
    Let your work talk for you

  9. #9
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: processEvents() and threads

    THATS the reason why i was trying to call processEvents() from another thread, thinking it would solve my problem..but evidently it doesnt save my life..

  10. #10
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: processEvents() and threads

    Hi,

    Can you try to add "processEvents" calls into the process function? If you have a loop, you can add it to be called every loop iteration, ...
    Òscar Llarch i Galán

  11. #11
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: processEvents() and threads

    well, i mentioned it before also..i have tried that and that does work..although the loading icon animates intermittently..but it definitely moves..but i've been asked to find "another" way of doing it..and now i m coming to the conclusion that perhaps it cant be done in any other way, if i m not missing anything that QT provides and i m not aware of or u guys are not aware of...

  12. #12
    Join Date
    Dec 2007
    Posts
    40
    Thanks
    6
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: processEvents() and threads

    this had to be! managerial decisions on how the code should execute (not meant against anyone, but I have had a fair share of these kind of things myself!!!)...
    but may be there is no way this can be achieved, unless ofcourse there is some obscure hard-to-find feature somewhere hidden in qt!!!
    Let your work talk for you

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

    Default Re: processEvents() and threads


  14. #14
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: processEvents() and threads

    yes, that was the first thing i looked at and i remember it was u who wrote that article great methods to avoid all freezing but nth worked for me...

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

    Default Re: processEvents() and threads

    They will work for you if you follow them I'd try the step-by-step approach in your situation - enter early into the event loop with a timer running, divide your calculations into chunks and use QTime::elapsed() to make sure you don't starve the event loop.

  16. #16
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: processEvents() and threads

    yes, if i divide my calculations into chunks, it IS solvable..but if i havent mentioned it earlier, i m not allowed to make ANY changes to the way currently all "calculations" are done..so my attempt was to fly past it and hdo it through a tread or start a timer with processEvents(), but none of them seem to work..also i mentioned earlier that if i put some calls to processEvents() inside the code of function where all "calculations" are done..the loading icon does animate! so my only concern is if i can bypass making ANY changes in the calculations function and still be able to solve the problem....i maybe m asking for too much here

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

    Default Re: processEvents() and threads

    Isn't placing processEvents() calls inside the calculation process also changing the way the calculations are done? I'm not sure why injecting processEvents() is fine and dividing the code into 10 methods is not.

  18. The following user says thank you to wysota for this useful post:

    talk2amulya (20th February 2009)

  19. #18
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: processEvents() and threads

    no, injecting processEvents() is NOT fine..thats why i m finding an alternate solution..the management is adamant at making no changes to the "calculation" function..and now the torch has been passed..i have been taken off the issue and sm QT guru would be looking after the issue..i m really looking forward to his stance on this thank you all for your time!

  20. #19
    Join Date
    Jan 2006
    Posts
    132
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: processEvents() and threads

    This may seem a elaborate solution just to get marketing happy, but how about spawning a mini-app in a second process just displaying the splash?

  21. The following user says thank you to seneca for this useful post:

    talk2amulya (20th February 2009)

  22. #20
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: processEvents() and threads

    wow, now thats smth that may catch their attention cuz they DO NOT wanna change ANTH in the calculation function...who knows..but thanks man, that might be a good thing to remember as solving a problem..just spawn another process

Similar Threads

  1. Once more: Threads in Qt4
    By high_flyer in forum Qt Programming
    Replies: 5
    Last Post: 9th August 2006, 18:35

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.