Results 1 to 6 of 6

Thread: Qt application output says crashed

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt application output says crashed

    Does the output show "-x-x-x- Count Reached 10 -x-x-x-" if you wait long enough?

    There is nothing wrong with your application, except that:
    • there is a race condition between slots: worker->stopThread() is connected to both timer.stop() and worker->deleteLater(); worker could be deleted first, thus preventing timer.stop() from being run. Since the order in which the slots are run is unspecified in general, this may or may not happen in practice.
    • the application never terminates. Nothing causes the event loop to exit.

    I cannot see why stopping the timer would be necessary. However, you should probably exit the event loop cleanly. Here is a proposal that exits the program after the worker has finished its work:
    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QCoreApplication a(argc, argv);
    4. QTimer timer;
    5. Worker worker; // No need to allocate this on the heap; the stack is fine, and the object will be automatically destroyed at the end of the function (just like a and timer)
    6. QCoreApplication::connect(&timer, SIGNAL(timeout()), &worker, SLOT(process()));
    7. QCoreApplication::connect(&worker, SIGNAL(stopThread()), &a, SLOT(quit()));
    8. timer.start(1000);
    9. return a.exec();
    10. }
    To copy to clipboard, switch view to plain text mode 

  2. The following user says thank you to yeye_olive for this useful post:

    rawfool (3rd August 2015)

  3. #2
    Join Date
    Sep 2011
    Location
    Bangalore
    Posts
    254
    Thanks
    92
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Qt application output says crashed

    Does the output show "-x-x-x- Count Reached 10 -x-x-x-" if you wait long enough?
    Yes! The output prints the same.

    the application never terminates. Nothing causes the event loop to exit.
    I'm closing the console window. So, doesn't that mean that a signal to terminate the application is emitted implicitly ?

    Your solution worked cleanly though, thank you.

  4. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt application output says crashed

    Quote Originally Posted by yeye_olive View Post
    there is a race condition between slots: worker->stopThread() is connected to both timer.stop() and worker->deleteLater(); worker could be deleted first, thus preventing timer.stop() from being run. Since the order in which the slots are run is unspecified in general, this may or may not happen in practice.
    Actually, as of Qt5 the order of slot invocations it now specified as being in order of connects.
    This is de-facto also the case for Qt4.

    Cheers,
    _

  5. The following user says thank you to anda_skoa for this useful post:

    rawfool (4th August 2015)

  6. #4
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt application output says crashed

    Quote Originally Posted by rawfool View Post
    I'm closing the console window. So, doesn't that mean that a signal to terminate the application is emitted implicitly ?
    No. It is possible to make this happen, but Qt offers no built-in platform-agnostic way to do it. There are several threads discussing solutions on this forum. That being said, the default behavior (the application is killed without having the opportunity to run clean-up code) is often acceptable.

    Quote Originally Posted by anda_skoa View Post
    Actually, as of Qt5 the order of slot invocations it now specified as being in order of connects. This is de-facto also the case for Qt4.
    Thanks, I must have missed that.

  7. The following user says thank you to yeye_olive for this useful post:

    rawfool (4th August 2015)

Similar Threads

  1. Replies: 1
    Last Post: 17th November 2015, 14:11
  2. prints nothing in application output
    By ramin.lich in forum Newbie
    Replies: 2
    Last Post: 1st October 2014, 09:46
  3. Application output pane
    By stef13013 in forum Newbie
    Replies: 2
    Last Post: 30th June 2013, 18:31
  4. Replies: 3
    Last Post: 27th August 2011, 21:44
  5. Error message: The Application crashed
    By josecarlosmissias in forum Newbie
    Replies: 13
    Last Post: 10th December 2009, 16:38

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.