Results 1 to 6 of 6

Thread: Qt application output says crashed

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2011
    Location
    Bangalore
    Posts
    254
    Thanks
    92
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Qt application output says crashed

    I have written a small console application that prints something on QTimer timeout. I have a counter, which emits a signal to stop the QTimer when it reaches a predetermined value. Everything looks fine, except the application output says crashed when I close the console.

    Qt Code:
    1. // main.cpp
    2. #include <QCoreApplication>
    3. #include <QDebug>
    4. #include "worker.h"
    5. #include <QThread>
    6. #include <QTimer>
    7. #include <QPointer>
    8.  
    9. int main(int argc, char *argv[])
    10. {
    11. QCoreApplication a(argc, argv);
    12.  
    13. QTimer timer;
    14. Worker * worker = new Worker;
    15. // I tried QPointer<Worker> worker = new Worker; also but still gives the same application output
    16.  
    17. QCoreApplication::connect(&timer, SIGNAL(timeout()), worker, SLOT(process()));
    18. QCoreApplication::connect(worker, SIGNAL(stopThread()), &timer, SLOT(stop()));
    19. QCoreApplication::connect(worker, SIGNAL(stopThread()), worker, SLOT(deleteLater()));
    20. timer.start(1000);
    21.  
    22. return a.exec();
    23. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. //worker.h
    2. #ifndef WORKER_H
    3. #define WORKER_H
    4.  
    5. #include <QObject>
    6.  
    7. class Worker : public QObject
    8. {
    9. Q_OBJECT
    10.  
    11. int nCounter;
    12. public:
    13. explicit Worker(QObject *parent = 0);
    14. ~Worker();
    15.  
    16. signals:
    17. void stopThread(void);
    18. public slots:
    19. void process(void);
    20. };
    21.  
    22. #endif // WORKER_H
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. // worker.cpp
    2. #include "worker.h"
    3. #include <QDebug>
    4. #include <QTime>
    5. #include <QThread>
    6.  
    7. Worker::Worker(QObject *parent) : QObject(parent),
    8. nCounter(0)
    9. {}
    10.  
    11. Worker::~Worker()
    12. {
    13.  
    14. }
    15.  
    16. void Worker::process(void)
    17. {
    18. nCounter++;
    19. qDebug() << QTime::currentTime().toString("hh:mm:ss");
    20. if (nCounter == 10)
    21. {
    22. qDebug() << "-x-x-x- Count Reached 10 -x-x-x-";
    23. emit stopThread();
    24. }
    25. }
    To copy to clipboard, switch view to plain text mode 

    Kindly help me identify the why the message says the application crashes.
    Qt Code:
    1. Starting /home/rahul/Documents/build-qonsole-Desktop_Qt_5_4_1_GCC_32bit-Debug/qonsole...
    2. /home/rahul/Documents/build-qonsole-Desktop_Qt_5_4_1_GCC_32bit-Debug/qonsole crashed
    To copy to clipboard, switch view to plain text mode 
    Last edited by rawfool; 3rd August 2015 at 17:06.

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.