Results 1 to 8 of 8

Thread: For loop and While loop handling.

  1. #1
    Join Date
    Oct 2012
    Posts
    27
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default For loop and While loop handling.

    Hi!

    Im have a problem in handling the For loop and While loop. I put the While loop inside the For loop. Inside the For loop and While loop, i inserted the qApp->processEvents for me to be able to interact with the UI while the loop is on-going process. But i encounter cases that the application crashes while doing the process. is there any better approach for this? when i ran the application with qt environment, it doesn't crash but if i ran the application w/out qt, several times it crashes yet few times it doesn't. It seems its not stable.

    Pls send your inputs guys!

    Thanks!

  2. #2
    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 Re: For loop and While loop handling.

    You didn't write what You do in the loop's so I can't comment about crashes, well except if You use recursion then there is a limitation how many iteration can be rune before You crash (for my code It was around 9k or so).
    As for the loops I do it with the QTimer::singleshot() approach, something like this:

    Qt Code:
    1. void myClassBasedOnQObject::doSomeWork()
    2. {
    3. if (isDone) {
    4. emit isDone();
    5. return;
    6. }
    7.  
    8. // do work here
    9.  
    10. QTimer::singleShot(0, this, SLOT(doSomeWork()));
    11. }
    To copy to clipboard, switch view to plain text mode 

    It allows application to normally process main event loop, of course if Your task in doSomeWork() will take more time then You will notice GUI hangs, if so then use QThreads.
    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.

  3. #3
    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: For loop and While loop handling.

    Here is an article to read too: [wiki]Keeping the GUI Responsive[/wiki]
    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.


  4. #4
    Join Date
    Oct 2012
    Posts
    27
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: For loop and While loop handling.

    Thanks guys for the inputs. I took the details of the cause of the crash. It points out: APPCRASH Cause of crash: ntdll.dll. Do you have any idea regarding this dll?

  5. #5
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: For loop and While loop handling.

    when i ran the application with qt environment, it doesn't crash but if i ran the application w/out qt
    What do you mean by "qt environment" and "w/out qt". I am wondering how can you use qApp->processEvents with out "qt environment"
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  6. #6
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: For loop and While loop handling.

    Quote Originally Posted by kiboi View Post
    Thanks guys for the inputs. I took the details of the cause of the crash. It points out: APPCRASH Cause of crash: ntdll.dll. Do you have any idea regarding this dll?
    you dont need to worry about that! that is not the problem!
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  7. #7
    Join Date
    Oct 2012
    Posts
    27
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: For loop and While loop handling.

    hi santosh,
    With "qt environment" means the host pc has an installed qt creator while "w/out qt" means the pc doesn't have a qt creator. I'm pointing this out since I have created an installer and ran the exe without using the qt.

  8. #8
    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: For loop and While loop handling.

    Quote Originally Posted by kiboi View Post
    I'm pointing this out since I have created an installer and ran the exe without using the qt.
    If your application requires Qt then you can't run it without Qt. You need to deploy Qt dlls along with your application.
    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.


Similar Threads

  1. Using a QProgressbar in a For Loop
    By kiboi in forum Newbie
    Replies: 5
    Last Post: 22nd October 2012, 09:19
  2. For loop error
    By silur in forum Qt Programming
    Replies: 1
    Last Post: 24th August 2012, 15:32
  3. Replies: 4
    Last Post: 6th August 2011, 01:40
  4. Handling specific events only in the main loop
    By Patje in forum Qt Programming
    Replies: 1
    Last Post: 1st April 2011, 13:24
  5. Main loop thread loop communication
    By mcsahin in forum Qt Programming
    Replies: 7
    Last Post: 25th January 2011, 16:31

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.