Results 1 to 19 of 19

Thread: SIGSEGV Error: Very Strange

  1. #1
    Join Date
    May 2011
    Posts
    46
    Thanks
    5

    Default SIGSEGV Error: Very Strange

    MainWindow.h
    Qt Code:
    1. #include <QMainWindow>
    2.  
    3. class MainWindow : public QMainWindow
    4. {
    5. Q_OBJECT
    6. public:
    7. explicit MainWindow(QWidget *parent = 0);
    8. };
    To copy to clipboard, switch view to plain text mode 

    MainWindow.cpp
    Qt Code:
    1. #include "MainWindow.h"
    2.  
    3. MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
    4. {
    5. #ifdef QT_DEBUG
    6. setWindowTitle("DEBUG");
    7. #else
    8. setWindowTitle("RELEASE");
    9. #endif
    10.  
    11. }
    To copy to clipboard, switch view to plain text mode 

    Application.h
    Qt Code:
    1. #include <QApplication>
    2.  
    3. class MainWindow;
    4.  
    5. class Application : public QApplication
    6. {
    7. public:
    8. Application(int argc, char** argv);
    9. ~Application();
    10. MainWindow* mainWindow() const;
    11. private:
    12. MainWindow* _mainWindow;
    13. };
    To copy to clipboard, switch view to plain text mode 
    Application.cpp
    Qt Code:
    1. #include "Application.h"
    2. #include "MainWindow.h"
    3.  
    4. Application::Application(int argc, char** argv) : QApplication(argc, argv)
    5. {
    6. _mainWindow = new MainWindow;
    7. }
    8.  
    9. Application::~Application(){
    10. delete _mainWindow;
    11. _mainWindow = 0;
    12. }
    13.  
    14. MainWindow * Application::mainWindow() const
    15. {
    16. return _mainWindow;
    17. }
    To copy to clipboard, switch view to plain text mode 

    main.cpp
    Qt Code:
    1. #include "Application.h"
    2. #include "MainWindow.h"
    3.  
    4. int main(int argc, char** argv)
    5. {
    6. Application app(argc, argv);
    7. app.mainWindow()->show();
    8. return app.exec();
    9. }
    To copy to clipboard, switch view to plain text mode 


    The code above run perfectly fine under release build, but will cause SIGSEGV Error everytime under debug build.
    My system is Ubuntu 11.04 64-bits, Qt 4.8/4.7.4

  2. #2
    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: SIGSEGV Error: Very Strange

    When does SIGSEGV error occur?

    You need to have virtual destructor
    Qt Code:
    1. virtual ~Application()
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    May 2011
    Posts
    46
    Thanks
    5

    Default Re: SIGSEGV Error: Very Strange

    Quote Originally Posted by Santosh Reddy View Post
    When does SIGSEGV error occur?

    You need to have virtual destructor
    Qt Code:
    1. virtual ~Application()
    To copy to clipboard, switch view to plain text mode 
    Exact same thing happens even after I added virtual.
    The error occur in qwidget.h at line 494
    Qt Code:
    1. inline void show() { setVisible(true); }
    To copy to clipboard, switch view to plain text mode 

    basically when I call "app.mainWindow()->show();" in main.

  4. #4
    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: SIGSEGV Error: Very Strange

    Does app.mainWindow() return a non-null pointer?
    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.


  5. #5
    Join Date
    May 2011
    Posts
    46
    Thanks
    5

    Default Re: SIGSEGV Error: Very Strange

    Quote Originally Posted by wysota View Post
    Does app.mainWindow() return a non-null pointer?
    Yes, it is not null.

  6. #6
    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: SIGSEGV Error: Very Strange

    What does the backtrace say?
    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.


  7. #7
    Join Date
    May 2011
    Posts
    46
    Thanks
    5

    Default Re: SIGSEGV Error: Very Strange

    Quote Originally Posted by wysota View Post
    What does the backtrace say?
    Qt Code:
    1. Thread 1 (Thread 0x7ffff7fca7a0 (LWP 12791)):
    2. #0 0x00007ffff5d9b49f in ?? () from /lib/x86_64-linux-gnu/libc.so.6
    3. No symbol table info available.
    4. #1 0x00007ffff4310382 in XSetCommand () from /usr/lib/x86_64-linux-gnu/libX11.so.6
    5. No symbol table info available.
    6. #2 0x00007ffff4315169 in XSetWMProperties () from /usr/lib/x86_64-linux-gnu/libX11.so.6
    7. No symbol table info available.
    8. #3 0x00007ffff735420a in QWidgetPrivate::create_sys(unsigned long, bool, bool) () from /usr/local/Trolltech/Qt-4.8.0/lib/libQtGui.so.4
    9. No symbol table info available.
    10. #4 0x00007ffff73058e5 in QWidget::create(unsigned long, bool, bool) () from /usr/local/Trolltech/Qt-4.8.0/lib/libQtGui.so.4
    11. No symbol table info available.
    12. #5 0x00007ffff730f3d1 in QWidget::setVisible(bool) () from /usr/local/Trolltech/Qt-4.8.0/lib/libQtGui.so.4
    13. No symbol table info available.
    14. #6 0x0000000000402a5c in QWidget::show (this=0x609ab0) at /usr/local/Trolltech/Qt-4.8.0/include/QtGui/qwidget.h:494
    15. No locals.
    16. #7 0x00000000004029fd in main (argc=1, argv=0x7fffffffe6e8) at Main.cpp:7
    17. app = {<QApplication> = {<No data fields>}, _mainWindow = 0x609ab0}
    To copy to clipboard, switch view to plain text mode 

  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: SIGSEGV Error: Very Strange

    Does it work if you use a stable version of Qt?
    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.


  9. #9
    Join Date
    May 2011
    Posts
    46
    Thanks
    5

    Default Re: SIGSEGV Error: Very Strange

    Quote Originally Posted by wysota View Post
    Does it work if you use a stable version of Qt?
    Same result with Qt 4.7.4

  10. #10
    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: SIGSEGV Error: Very Strange

    It seems odd the application crashes when setting window properties. What window manager are you using? Does the program work if you rewrite it as:

    Qt Code:
    1. int main(int argc, char **argv) {
    2. QApplication app(argc, argv);
    3. mw.setWindowTitle("DEBUG");
    4. mw.show();
    5. return app.exec();
    6. }
    To copy to clipboard, switch view to plain text mode 
    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.


  11. #11
    Join Date
    May 2011
    Posts
    46
    Thanks
    5

    Default Re: SIGSEGV Error: Very Strange

    Quote Originally Posted by wysota View Post
    It seems odd the application crashes when setting window properties. What window manager are you using? Does the program work if you rewrite it as:

    Qt Code:
    1. int main(int argc, char **argv) {
    2. QApplication app(argc, argv);
    3. mw.setWindowTitle("DEBUG");
    4. mw.show();
    5. return app.exec();
    6. }
    To copy to clipboard, switch view to plain text mode 
    This works fine.


    Added after 10 minutes:


    Ok, now this code will reproduce the issue

    Qt Code:
    1. #include <QWidget>
    2. #include <QApplication>
    3.  
    4. class MyApplication : public QApplication
    5. {
    6. public:
    7. MyApplication(int argc, char** argv) : QApplication(argc, argv){}
    8. };
    9.  
    10. int main(int argc, char** argv)
    11. {
    12. MyApplication app(argc, argv);
    13.  
    14. // fail on this line when CONFIG+=debug
    15. // (qmake my_project.pro -r -spec linux-g++-64 CONFIG+=debug)
    16. w.show();
    17. return app.exec();
    18. }
    To copy to clipboard, switch view to plain text mode 

    If I change "MyApplication app(argc, argv);" to "QApplication app(argc, argv);", everything will works fine
    Last edited by grayfox; 10th October 2011 at 15:23.

  12. #12
    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: SIGSEGV Error: Very Strange

    And this?

    Qt Code:
    1. class MainWindow : public QMainWindow {
    2. public:
    3. MainWindow() : QMainWindow() { setWindowTitle("DEBUG"); }
    4. };
    5.  
    6. int main(int argc, char **argv) {
    7. QApplication app(argc, argv);
    8. MainWindow mw;
    9. mw.show();
    10. return app.exec();
    11. }
    To copy to clipboard, switch view to plain text mode 

    If it works then check this:

    Qt Code:
    1. class MainWindow : public QMainWindow {
    2. public:
    3. MainWindow() : QMainWindow() { setWindowTitle("DEBUG"); }
    4. };
    5.  
    6. class Application : public QApplication {
    7. public:
    8. Application(int argc, char **argv) : QApplication(argc, argv) {}
    9. };
    10.  
    11. int main(int argc, char **argv) {
    12. Application app(argc, argv);
    13. MainWindow mw;
    14. mw.show();
    15. return app.exec();
    16. }
    To copy to clipboard, switch view to plain text mode 

    and then this one:

    Qt Code:
    1. class MainWindow : public QMainWindow {
    2. public:
    3. MainWindow() : QMainWindow() { setWindowTitle("DEBUG"); }
    4. };
    5.  
    6. class Application : public QApplication {
    7. public:
    8. Application(int argc, char **argv) : QApplication(argc, argv) {}
    9. MainWindow *mainWindow() const { return &mw; }
    10. private:
    11. MainWindow mw;
    12. };
    13.  
    14. int main(int argc, char **argv) {
    15. Application app(argc, argv);
    16. app.mainWindow()->show();
    17. return app.exec();
    18. }
    To copy to clipboard, switch view to plain text mode 
    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.


  13. #13
    Join Date
    May 2011
    Posts
    46
    Thanks
    5

    Default Re: SIGSEGV Error: Very Strange

    First 2 examples work, but the third one can't compile on line
    Qt Code:
    1. MainWindow *mainWindow() const { return &mw; }
    To copy to clipboard, switch view to plain text mode 
    error: invalid conversion from ‘const MainWindow*’ to ‘MainWindow*’
    I removed the 'const' and it compiles, this time, it doesn't work, exact same problem, OK in release mode, error in debug mode, same result with Qt4.7.4 and Qt4.8

  14. #14
    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: SIGSEGV Error: Very Strange

    Ok, then this should work:
    Qt Code:
    1. class MainWindow : public QMainWindow {
    2. public:
    3. MainWindow() : QMainWindow() { setWindowTitle("DEBUG"); }
    4. };
    5.  
    6. class Application : public QApplication {
    7. public:
    8. Application(int argc, char **argv) : QApplication(argc, argv) { mw = 0; }
    9. void init() {
    10. mw = new MainWindow;
    11. }
    12. ~Application() { delete mw; }
    13. MainWindow *mainWindow() const { return mw; }
    14. private:
    15. MainWindow *mw;
    16. };
    17.  
    18. int main(int argc, char **argv) {
    19. Application app(argc, argv);
    20. app.init();
    21. app.mainWindow()->show();
    22. return app.exec();
    23. }
    To copy to clipboard, switch view to plain text mode 
    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.


  15. #15
    Join Date
    May 2011
    Posts
    46
    Thanks
    5

    Default Re: SIGSEGV Error: Very Strange

    The above code works, but the problem still exists.

    This code will fail when compiled under debug mode.
    Qt Code:
    1. #include <QWidget>
    2. #include <QApplication>
    3.  
    4. class Application : public QApplication
    5. {
    6. public:
    7. Application(int argc, char** argv) : QApplication(argc, argv){}
    8. };
    9.  
    10. int main(int argc, char** argv)
    11. {
    12. Application a(argc, argv);
    13. w.show(); // fail
    14. return a.exec();
    15. }
    To copy to clipboard, switch view to plain text mode 

    The backtrace is:
    Qt Code:
    1. Thread 1 (Thread 0x7ffff7fca7a0 (LWP 25415)):
    2. #0 0x00007ffff5d9b49f in ?? () from /lib/x86_64-linux-gnu/libc.so.6
    3. No symbol table info available.
    4. #1 0x00007ffff4310382 in XSetCommand () from /usr/lib/x86_64-linux-gnu/libX11.so.6
    5. No symbol table info available.
    6. #2 0x00007ffff4315169 in XSetWMProperties () from /usr/lib/x86_64-linux-gnu/libX11.so.6
    7. No symbol table info available.
    8. #3 0x00007ffff735420a in QWidgetPrivate::create_sys(unsigned long, bool, bool) () from /usr/local/Trolltech/Qt-4.8.0/lib/libQtGui.so.4
    9. No symbol table info available.
    10. #4 0x00007ffff73058e5 in QWidget::create(unsigned long, bool, bool) () from /usr/local/Trolltech/Qt-4.8.0/lib/libQtGui.so.4
    11. No symbol table info available.
    12. #5 0x00007ffff730f3d1 in QWidget::setVisible(bool) () from /usr/local/Trolltech/Qt-4.8.0/lib/libQtGui.so.4
    13. No symbol table info available.
    14. #6 0x0000000000401226 in QWidget::show (this=0x7fffffffe5b0) at /usr/local/Trolltech/Qt-4.8.0/include/QtGui/qwidget.h:494
    15. No locals.
    16. #7 0x00000000004011ab in main (argc=1, argv=0x7fffffffe6f8) at Main.cpp:14
    17. a = {<QApplication> = {<No data fields>}, <No data fields>}
    18. w = <incomplete type>
    To copy to clipboard, switch view to plain text mode 

  16. #16
    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: SIGSEGV Error: Very Strange

    Change the Application constructor to:
    Qt Code:
    1. Application(int &argc, char **argv) : QApplication (argc, argv) {}
    To copy to clipboard, switch view to plain text mode 
    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.


  17. The following user says thank you to wysota for this useful post:

    grayfox (11th October 2011)

  18. #17
    Join Date
    Sep 2011
    Posts
    7
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: SIGSEGV Error: Very Strange

    I just came across this very same issue under Fedora 15(x64) with Qt 4.7.4.

    Do you have any explanation as to *why* adding a reference to the constructor worked wysota? (and how you deduced that was the problem).

    Simon.

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

    Default Re: SIGSEGV Error: Very Strange

    http://developer.qt.nokia.com/doc/qt...plication.html
    make sure the signature matches. otherwise, in this case, qapplication is storing a referece to a temporary
    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.

  20. The following user says thank you to amleto for this useful post:

    simoncsmith (16th January 2012)

  21. #19
    Join Date
    Sep 2011
    Posts
    7
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: SIGSEGV Error: Very Strange

    Thanks Amleto - I have to admit that I did not see that QApplication takes a *reference* to an integer in its prototype, most likely because I'm so used to seeing it without it!

Similar Threads

  1. Qt OpenCV SIGSEGV error help
    By bobo in forum Newbie
    Replies: 3
    Last Post: 13th June 2011, 21:03
  2. Strange Error
    By keeperofthegrove in forum Newbie
    Replies: 4
    Last Post: 22nd October 2008, 15:16
  3. strange QT error out of nowhere
    By Penut in forum Qt Programming
    Replies: 5
    Last Post: 14th August 2008, 02:46
  4. Strange error
    By joseph in forum General Programming
    Replies: 3
    Last Post: 8th February 2008, 14:32
  5. Strange Make Error: ld.exe?
    By Backslash in forum Newbie
    Replies: 2
    Last Post: 7th August 2007, 18:33

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.