Results 1 to 10 of 10

Thread: using assert, assertion failed, QTimerEvent keeps getting called! (qt3.3.8, vs2005)

  1. #1
    Join Date
    May 2010
    Posts
    3
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default using assert, assertion failed, QTimerEvent keeps getting called! (qt3.3.8, vs2005)

    using qt3.3.8, vs2005 sp1

    hi, i have narrowed my problem to the following:
    created the simplest qt program, with QApplication and a simple qobject with QTimerEvent and in the timer event i called assert(0) to raise an assertion failure.
    started the timerEvent and found that the timerevent keeps getting called (and i get an assertion failure again and again)
    of course this is not desirable, i want the program to stop.
    all the code up to the assertion (and non after) will be called again and again.
    any ideas?

    thanks for you help,

    Roy.

  2. #2
    Join Date
    Feb 2011
    Posts
    5
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: using assert, assertion failed, QTimerEvent keeps getting called! (qt3.3.8, vs200

    The same thing happened to me too!
    I tried using Q_ASSERT macro, but with no success. when I called abort() directly to terminate the proccess, it rendered the same results.
    When I tried this with QT 4.5 it worked as desired, however I'm obliged to use QT 3.3.8 in my workplace.

    could anyone reproduce this behaviour?
    is there a solution to this problem?

    thanks,
    Jonathan

  3. #3
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: using assert, assertion failed, QTimerEvent keeps getting called! (qt3.3.8, vs200

    From qglobal.h in the Qt 3.3.8 source code:
    Qt Code:
    1. #if !defined(Q_ASSERT)
    2. # if defined(QT_CHECK_STATE)
    3. # if defined(QT_FATAL_ASSERT)
    4. # define Q_ASSERT(x) ((x) ? (void)0 : qFatal("ASSERT: \"%s\" in %s (%d)",#x,__FILE__,__LINE__))
    5. # else
    6. # define Q_ASSERT(x) ((x) ? (void)0 : qWarning("ASSERT: \"%s\" in %s (%d)",#x,__FILE__,__LINE__))
    7. # endif
    8. # else
    9. # define Q_ASSERT(x)
    10. # endif
    11. #endif
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Feb 2011
    Posts
    5
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: using assert, assertion failed, QTimerEvent keeps getting called! (qt3.3.8, vs200

    Thanks for your reply.

    I'm aware of the definition of Q_ASSERT but I don't see how this can help me.
    I also tried calling qFatal(), but still the results are the same.

    Do you have any idea how to solve it, and change the behavior of assertion in qt 3.3.8 loop?

    Thanks.

  5. #5
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: using assert, assertion failed, QTimerEvent keeps getting called! (qt3.3.8, vs200

    As you can see from the source code if QT_FATAL_ASSERT isn't defined your app will call qWarning. To make your program exit (i.e. call qFatal) upon an assert failure you need to define the flag.

    You can put the following statement as the first line of your .cpp file:
    Qt Code:
    1. #define QT_FATAL_ASSERT
    To copy to clipboard, switch view to plain text mode 
    Or put the following in your .pro file:
    Qt Code:
    1. DEFINES += QT_FATAL_ASSERT
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Feb 2011
    Posts
    5
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: using assert, assertion failed, QTimerEvent keeps getting called! (qt3.3.8, vs200

    I tried defining QT_FATAL_ASSERT and I got an assertion failed window, but the program is still running and the timer is still getting called.

    Here is a simple example of what I'm trying to do:
    Qt Code:
    1. #include <cassert>
    2. class MyObject : public QObject
    3. {
    4. public:
    5. MyObject() { startTimer(100); }
    6.  
    7. virtual void timerEvent(QTimerEvent* e)
    8. {
    9. cout<<"beforeAssert";
    10. assert(0);
    11. cout<<"afterAssert";
    12. }
    13. };
    14.  
    15. ...
    16.  
    17. int main(int argc, char** argv)
    18. {
    19. QApplication qApp(argc, argv);
    20.  
    21. MyObject object;
    22.  
    23. return (qApp.exec());
    24. }
    To copy to clipboard, switch view to plain text mode 

    this code prints "beforeAssert" then pops an assertion failed window, but instead of stopping there it keeps on printing ("beforeAssert") and popping messages, until I manually kill the process.

    note: anything after the assert will not be called (i.e "afterAssert will not be printed")

  7. #7
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: using assert, assertion failed, QTimerEvent keeps getting called! (qt3.3.8, vs200

    QT_FATAL_ASSERT works with Q_ASSERT.

    The following works on my box:
    Qt Code:
    1. #define QT_FATAL_ASSERT
    2. #include <qapplication.h>
    3. #include <qobject.h>
    4.  
    5. class Object : public QObject
    6. {
    7. Q_OBJECT
    8. public:
    9. Object(){
    10. startTimer(1000);
    11. }
    12.  
    13. void timerEvent(QTimerEvent *event){
    14. Q_ASSERT(0);
    15. }
    16. };
    17.  
    18. int main(int argc, char *argv[]){
    19.  
    20. QApplication app(argc, argv);
    21. Object obj;
    22. app.exec();
    23. }
    24.  
    25. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 

    And so does your app with modifications:
    Qt Code:
    1. #include <cassert>
    2. #include <qobject.h>
    3. #include <qapplication.h>
    4. #include <iostream>
    5.  
    6. class MyObject : public QObject
    7. {
    8. public:
    9. MyObject() { startTimer(100); }
    10.  
    11. virtual void timerEvent(QTimerEvent* e)
    12. {
    13. std::cout<<"beforeAssert" << std::endl;
    14. assert(0);
    15. std::cout<<"afterAssert";
    16. }
    17. };
    18.  
    19.  
    20. int main(int argc, char** argv)
    21. {
    22. QApplication app(argc, argv);
    23.  
    24. MyObject object;
    25.  
    26. return (app.exec());
    27. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by norobro; 22nd February 2011 at 16:45. Reason: had Qt4 includes

  8. #8
    Join Date
    Feb 2011
    Posts
    5
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: using assert, assertion failed, QTimerEvent keeps getting called! (qt3.3.8, vs200

    are you using QT 3.3.8?

  9. #9
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: using assert, assertion failed, QTimerEvent keeps getting called! (qt3.3.8, vs200

    Quote Originally Posted by jonspieg View Post
    are you using QT 3.3.8?
    Yep. Qt 3.3.8 on a Debian Sid machine. Does the first program in post #7, with Q_ASSERT, not halt?

    Maybe it's a Windows thang

  10. #10
    Join Date
    Feb 2011
    Posts
    5
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: using assert, assertion failed, QTimerEvent keeps getting called! (qt3.3.8, vs200

    yep. just won't halt...
    thanks for the help though

    maybe someone else can reproduce this in a windows environment?

Similar Threads

  1. Replies: 2
    Last Post: 17th December 2010, 08:26
  2. Replies: 7
    Last Post: 26th July 2008, 13:24
  3. "Debug Assertion failed" in debug mode
    By hed in forum Qt Programming
    Replies: 10
    Last Post: 4th February 2008, 12:10
  4. Debug Assertion Failed
    By ^NyAw^ in forum General Programming
    Replies: 5
    Last Post: 28th December 2007, 11:48
  5. ASSERT(Failed assertion in Qt == Qt bug)
    By 0xBulbizarre in forum Qt Programming
    Replies: 1
    Last Post: 20th March 2006, 19:06

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.