SIGSEGV Error: Very Strange
MainWindow.h
Code:
#include <QMainWindow>
{
Q_OBJECT
public:
explicit MainWindow
(QWidget *parent
= 0);
};
MainWindow.cpp
Code:
#include "MainWindow.h"
{
#ifdef QT_DEBUG
setWindowTitle("DEBUG");
#else
setWindowTitle("RELEASE");
#endif
}
Application.h
Code:
#include <QApplication>
class MainWindow;
{
public:
Application(int argc, char** argv);
~Application();
MainWindow* mainWindow() const;
private:
MainWindow* _mainWindow;
};
Application.cpp
Code:
#include "Application.h"
#include "MainWindow.h"
Application
::Application(int argc,
char** argv
) : QApplication(argc, argv
){
_mainWindow = new MainWindow;
}
Application::~Application(){
delete _mainWindow;
_mainWindow = 0;
}
MainWindow * Application::mainWindow() const
{
return _mainWindow;
}
main.cpp
Code:
#include "Application.h"
#include "MainWindow.h"
int main(int argc, char** argv)
{
Application app(argc, argv);
app.mainWindow()->show();
return app.exec();
}
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
Re: SIGSEGV Error: Very Strange
When does SIGSEGV error occur?
You need to have virtual destructor
Code:
virtual ~Application()
Re: SIGSEGV Error: Very Strange
Quote:
Originally Posted by
Santosh Reddy
When does SIGSEGV error occur?
You need to have virtual destructor
Code:
virtual ~Application()
Exact same thing happens even after I added virtual.
The error occur in qwidget.h at line 494
Code:
inline void show() { setVisible(true); }
basically when I call "app.mainWindow()->show();" in main.
Re: SIGSEGV Error: Very Strange
Does app.mainWindow() return a non-null pointer?
Re: SIGSEGV Error: Very Strange
Quote:
Originally Posted by
wysota
Does app.mainWindow() return a non-null pointer?
Yes, it is not null.
Re: SIGSEGV Error: Very Strange
What does the backtrace say?
Re: SIGSEGV Error: Very Strange
Quote:
Originally Posted by
wysota
What does the backtrace say?
Code:
Thread 1 (Thread 0x7ffff7fca7a0 (LWP 12791)):
#0 0x00007ffff5d9b49f in ?? () from /lib/x86_64-linux-gnu/libc.so.6
No symbol table info available.
#1 0x00007ffff4310382 in XSetCommand () from /usr/lib/x86_64-linux-gnu/libX11.so.6
No symbol table info available.
#2 0x00007ffff4315169 in XSetWMProperties () from /usr/lib/x86_64-linux-gnu/libX11.so.6
No symbol table info available.
#3 0x00007ffff735420a in QWidgetPrivate::create_sys(unsigned long, bool, bool) () from /usr/local/Trolltech/Qt-4.8.0/lib/libQtGui.so.4
No symbol table info available.
#4 0x00007ffff73058e5 in QWidget::create(unsigned long, bool, bool) () from /usr/local/Trolltech/Qt-4.8.0/lib/libQtGui.so.4
No symbol table info available.
#5 0x00007ffff730f3d1 in QWidget::setVisible(bool) () from /usr/local/Trolltech/Qt-4.8.0/lib/libQtGui.so.4
No symbol table info available.
#6 0x0000000000402a5c in QWidget::show (this=0x609ab0) at /usr/local/Trolltech/Qt-4.8.0/include/QtGui/qwidget.h:494
No locals.
#7 0x00000000004029fd in main (argc=1, argv=0x7fffffffe6e8) at Main.cpp:7
app = {<QApplication> = {<No data fields>}, _mainWindow = 0x609ab0}
Re: SIGSEGV Error: Very Strange
Does it work if you use a stable version of Qt?
Re: SIGSEGV Error: Very Strange
Quote:
Originally Posted by
wysota
Does it work if you use a stable version of Qt?
Same result with Qt 4.7.4
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:
Code:
int main(int argc, char **argv) {
mw.setWindowTitle("DEBUG");
mw.show();
return app.exec();
}
Re: SIGSEGV Error: Very Strange
Quote:
Originally Posted by
wysota
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:
Code:
int main(int argc, char **argv) {
mw.setWindowTitle("DEBUG");
mw.show();
return app.exec();
}
This works fine.
Added after 10 minutes:
Ok, now this code will reproduce the issue
Code:
#include <QWidget>
#include <QApplication>
{
public:
MyApplication
(int argc,
char** argv
) : QApplication(argc, argv
){}};
int main(int argc, char** argv)
{
MyApplication app(argc, argv);
// fail on this line when CONFIG+=debug
// (qmake my_project.pro -r -spec linux-g++-64 CONFIG+=debug)
w.show();
return app.exec();
}
If I change "MyApplication app(argc, argv);" to "QApplication app(argc, argv);", everything will works fine
Re: SIGSEGV Error: Very Strange
And this?
Code:
public:
MainWindow
() : QMainWindow() { setWindowTitle
("DEBUG");
}};
int main(int argc, char **argv) {
MainWindow mw;
mw.show();
return app.exec();
}
If it works then check this:
Code:
public:
MainWindow
() : QMainWindow() { setWindowTitle
("DEBUG");
}};
public:
Application
(int argc,
char **argv
) : QApplication(argc, argv
) {}};
int main(int argc, char **argv) {
Application app(argc, argv);
MainWindow mw;
mw.show();
return app.exec();
}
and then this one:
Code:
public:
MainWindow
() : QMainWindow() { setWindowTitle
("DEBUG");
}};
public:
Application
(int argc,
char **argv
) : QApplication(argc, argv
) {} MainWindow *mainWindow() const { return &mw; }
private:
MainWindow mw;
};
int main(int argc, char **argv) {
Application app(argc, argv);
app.mainWindow()->show();
return app.exec();
}
Re: SIGSEGV Error: Very Strange
First 2 examples work, but the third one can't compile on line
Code:
MainWindow *mainWindow() const { return &mw; }
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
Re: SIGSEGV Error: Very Strange
Ok, then this should work:
Code:
public:
MainWindow
() : QMainWindow() { setWindowTitle
("DEBUG");
}};
public:
Application
(int argc,
char **argv
) : QApplication(argc, argv
) { mw
= 0;
} void init() {
mw = new MainWindow;
}
~Application() { delete mw; }
MainWindow *mainWindow() const { return mw; }
private:
MainWindow *mw;
};
int main(int argc, char **argv) {
Application app(argc, argv);
app.init();
app.mainWindow()->show();
return app.exec();
}
Re: SIGSEGV Error: Very Strange
The above code works, but the problem still exists.
This code will fail when compiled under debug mode.
Code:
#include <QWidget>
#include <QApplication>
{
public:
Application
(int argc,
char** argv
) : QApplication(argc, argv
){}};
int main(int argc, char** argv)
{
Application a(argc, argv);
w.show(); // fail
return a.exec();
}
The backtrace is:
Code:
Thread 1 (Thread 0x7ffff7fca7a0 (LWP 25415)):
#0 0x00007ffff5d9b49f in ?? () from /lib/x86_64-linux-gnu/libc.so.6
No symbol table info available.
#1 0x00007ffff4310382 in XSetCommand () from /usr/lib/x86_64-linux-gnu/libX11.so.6
No symbol table info available.
#2 0x00007ffff4315169 in XSetWMProperties () from /usr/lib/x86_64-linux-gnu/libX11.so.6
No symbol table info available.
#3 0x00007ffff735420a in QWidgetPrivate::create_sys(unsigned long, bool, bool) () from /usr/local/Trolltech/Qt-4.8.0/lib/libQtGui.so.4
No symbol table info available.
#4 0x00007ffff73058e5 in QWidget::create(unsigned long, bool, bool) () from /usr/local/Trolltech/Qt-4.8.0/lib/libQtGui.so.4
No symbol table info available.
#5 0x00007ffff730f3d1 in QWidget::setVisible(bool) () from /usr/local/Trolltech/Qt-4.8.0/lib/libQtGui.so.4
No symbol table info available.
#6 0x0000000000401226 in QWidget::show (this=0x7fffffffe5b0) at /usr/local/Trolltech/Qt-4.8.0/include/QtGui/qwidget.h:494
No locals.
#7 0x00000000004011ab in main (argc=1, argv=0x7fffffffe6f8) at Main.cpp:14
a = {<QApplication> = {<No data fields>}, <No data fields>}
w = <incomplete type>
Re: SIGSEGV Error: Very Strange
Change the Application constructor to:
Code:
Application
(int &argc,
char **argv
) : QApplication (argc, argv
) {}
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.
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
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!