Results 1 to 5 of 5

Thread: Error "has triggered a breakpoint" when trying to call members of QSpinBox in Debug

  1. #1
    Join Date
    Jul 2015
    Posts
    17
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Error "has triggered a breakpoint" when trying to call members of QSpinBox in Debug

    Dear all,


    I am rather new to Qt and I am working on an application in which I have several ui-files which contain QSpinboxes. Those ui-files were generated while still using Qt 4.8.4-1. Now, I am using 5.4.1 (with Visual Studio 2012 and CMake) and I have observed the following strange behaviour which was not there while still working with Qt 4.8.4-1:
    When running the following code in DEBUG mode, then I get a runtime error "... has triggered a breakpoint". It is triggered after leaving the main method. There is no runtime error when running it in RELEASE.


    Qt Code:
    1. #include <QApplication>
    2. #include <QWidget>
    3. #include <QSpinBox>
    4. #include <qnamespace.h>
    5. #include <QFlags>
    6.  
    7. int main(int argc, char *argv[])
    8. {
    9. int i=777; //some random value
    10.  
    11. QApplication app(argc, argv);
    12.  
    13.  
    14. QSpinBox *sbxDuration = new QSpinBox();
    15.  
    16. //Call QSpinBox members
    17. //sbxDuration->setMinimum(1); // causes runtime error "... has triggered a breakpoint"
    18. sbxDuration->setMaximum(2); // does not trigger the runtime error
    19. //sbxDuration->setValue(1); // causes runtime error "... has triggered a breakpoint"
    20. //sbxDuration->setSingleStep(0); // causes runtime error "... has triggered a breakpoint"
    21.  
    22.  
    23. //Call QAbstractSpinBox members (none of these calls cause the runtime error)
    24. sbxDuration->setWrapping(true);
    25. sbxDuration->setFrame(true);
    26. QFlags<Qt::AlignmentFlag> flg;
    27. sbxDuration->setAlignment(flg);
    28. sbxDuration->setReadOnly(true);
    29. sbxDuration->setButtonSymbols(QAbstractSpinBox::NoButtons);
    30. sbxDuration->setAccelerated(false);
    31. sbxDuration->setCorrectionMode(QAbstractSpinBox::CorrectToPreviousValue);
    32.  
    33.  
    34. delete sbxDuration;
    35.  
    36. return i;
    37.  
    38. }
    39. // this results in
    40. // "... has exited with code 0 (0x0)." if runtime error occurs
    41. // "has exited with code 777 (0x309)." if no runtime error
    To copy to clipboard, switch view to plain text mode 

    I added a new system variable called “_NO_DEBUG_HEAP” with a value of “1” to Control Panel->System Properties->Advanced System Settings->Environment Variables->System Variables (http://stackoverflow.com/questions/6...-no-debug-heap). However, that did not help.
    My concern is that even if in my minimal example it seems to be only a problem in DEBUG mode, it will be a problem in the "real" application that I am working on.

    Does anybody have an idea how to locate the error?!?

    Thanks in advence!

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,118
    Thanks
    235
    Thanked 656 Times in 646 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Error "has triggered a breakpoint" when trying to call members of QSpinBox in Deb

    Well, normally, you don't create widgets just floating out in interstellar space and make random calls to member functions like your example does. You make a dialog or a main window, and its constructor takes the ui code and uses it to build the visible UI. Or you create a QWidget instance and call its show() method. And normally, none of this becomes visible until after the event loop is running (app.exec()).

    My guess is that because you've created your spin box on the heap and you aren't calling the show() or exec() methods, there's some spin box behavior that depends on one of these prerequisites and thus it blows up. Make a proper Qt GUI application and try again.

  3. #3
    Join Date
    Jul 2015
    Posts
    17
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Error "has triggered a breakpoint" when trying to call members of QSpinBox in Deb

    Dear d_stranz,

    I posted the minimal example for better overview, however, the problem is still there, if i incorporate it into a "proper GUI application" (see below).

    main.cpp:
    Qt Code:
    1. #include <QApplication>
    2.  
    3. #include <TestWindow.h>
    4.  
    5. int main(int argc, char *argv[])
    6. {
    7. int i=777; //some random value
    8.  
    9. QApplication app(argc, argv);
    10. TestWindow w;
    11. w.show();
    12. i= app.exec();
    13.  
    14. return i;
    15. }
    To copy to clipboard, switch view to plain text mode 


    TestWindow.h:
    Qt Code:
    1. #ifndef TESTWINDOW_H
    2. #define TESTWINDOW_H
    3.  
    4. #include <QMainWindow>
    5.  
    6. namespace Ui {
    7. class TestWindow;
    8. }
    9.  
    10. class TestWindow : public QMainWindow
    11. {
    12. Q_OBJECT
    13.  
    14. public:
    15. explicit TestWindow(QWidget *parent = 0);
    16. ~TestWindow();
    17.  
    18. private:
    19. Ui::TestWindow *ui;
    20. };
    21.  
    22. #endif // TESTWINDOW_H
    To copy to clipboard, switch view to plain text mode 


    TestWindow.cpp:
    Qt Code:
    1. #include "TestWindow.h"
    2. #include "ui_TestWindow.h"
    3.  
    4. TestWindow::TestWindow(QWidget *parent) :
    5. QMainWindow(parent),
    6. ui(new Ui::TestWindow)
    7. {
    8. ui->setupUi(this);
    9. }
    10.  
    11. TestWindow::~TestWindow()
    12. {
    13. delete ui;
    14. }
    To copy to clipboard, switch view to plain text mode 


    TestWindow.ui:
    Qt Code:
    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <?xml version="1.0" encoding="UTF-8"?>
    3. <ui version="4.0">
    4. <class>TestWindow</class>
    5. <widget class="QWidget" name="TestWindow">
    6. <property name="geometry">
    7. <rect>
    8. <x>0</x>
    9. <y>0</y>
    10. <width>400</width>
    11. <height>300</height>
    12. </rect>
    13. </property>
    14. <property name="windowTitle">
    15. <string>Form</string>
    16. </property>
    17. <widget class="QSpinBox" name="spinBox">
    18. <property name="geometry">
    19. <rect>
    20. <x>100</x>
    21. <y>70</y>
    22. <width>42</width>
    23. <height>22</height>
    24. </rect>
    25. </property>
    26. </widget>
    27. </widget>
    28. <resources/>
    29. <connections/>
    30. </ui>
    To copy to clipboard, switch view to plain text mode 


    If I run this in DEBUG, then I get the runtime error "..has triggered a breakpoint" as soon as I close the window.
    If I replace the QSpinBox with a QLineEdit, then the runtime error at closing of the window disappears.
    However, if I add some text to the QLineEdit while the window is open, I get the same error. It seems that the application can not handle it, if any QWidgets (like QLineEdit or QSpinBox) hold data during runtime.

    I also noticed that when compiling in DEBUG, I get the warning
    "Warning 1 warning LNK4075: ignoring '/INCREMENTAL' due to '/LTCG' specification C:\svn\SpielwieseQt\_build_x64_vc11\LINK". Not sure, if this is related to the problem I described.

    Any ideas on how to approach this?

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,118
    Thanks
    235
    Thanked 656 Times in 646 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Error "has triggered a breakpoint" when trying to call members of QSpinBox in Deb

    When I create a new project and paste your code into the UI file, it runs just fine. This is with VS 2013, Qt 5.4.1. I doubt the VS version has anything to do with it. Are you sure you are linking with the same version of Qt that is loaded at run-time? That is, is your PATH environment variable pointing to the same location for Qt runtime DLLs as you are specifying in your linker options?

  5. #5
    Join Date
    Jul 2015
    Posts
    17
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Error "has triggered a breakpoint" when trying to call members of QSpinBox in Deb

    It turned out that it was a problem with the 5.4.1 build of the lib. Using another build (Qt5.5) solved the problem.

Similar Threads

  1. Replies: 5
    Last Post: 15th August 2014, 03:04
  2. Replies: 1
    Last Post: 10th October 2012, 08:46
  3. Replies: 0
    Last Post: 21st February 2010, 18:09
  4. Replies: 3
    Last Post: 15th February 2010, 17:27
  5. Replies: 3
    Last Post: 29th August 2009, 22:24

Tags for this Thread

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.