PDA

View Full Version : QMessabeBox cause Segmentation Fault



piorekf
6th March 2011, 01:26
I have following code:

void MainWindow::check_for_updates()
{
QNetworkAccessManager *qnam = new QNetworkAccessManager(this);
reply = qnam->get(QNetworkRequest((QUrl)"http://piorekf.org/plug/VERSION"));
connect(reply, SIGNAL(readyRead()), this, SLOT(httpReadyRead()));
}

void MainWindow::httpReadyRead()
{
if(reply->readAll() > VERSION)
{
QLabel *label = new QLabel(tr("<b>Update available!</b>"), this);
ui->statusBar->addWidget(label);
QMessageBox *msgbx = new QMessageBox;
msgbx->setWindowTitle(tr("Update"));
msgbx->setText(tr("<b>Update available!</b>"));
msgbx->setInformativeText(tr("Check homepage for new version"));
msgbx->setIcon(QMessageBox::Information);
msgbx->show();
// QMessageBox::information(this, "Update", "<b>Update available!</b><br>Check homepage for new version.");
}
else
ui->statusBar->showMessage(tr("You are using the newest version"), 5000);
}

The problem is that when I use static function (here commented) or change line 19 to "msgbx->exec();" I get Segmentation Fault. I'm using Qt 4.7.2 on Linux. I'm not 100% sure but I think that on Qt 4.7.1 everything was fine and there was no segfault. Any ideas?

wysota
6th March 2011, 08:23
Please post a backtrace of the crash.

piorekf
6th March 2011, 12:40
Sorry, I forgot about it. Here it is:

Program received signal SIGSEGV, Segmentation fault.
0x00000038bd058192 in ?? () from /usr/lib64/qt4/libQtNetwork.so.4
(gdb) bt
#0 0x00000038bd058192 in ?? () from /usr/lib64/qt4/libQtNetwork.so.4
#1 0x00000038bd058bfc in ?? () from /usr/lib64/qt4/libQtNetwork.so.4
#2 0x00000038bb173897 in QMetaObject::activate(QObject*, QMetaObject const*, int, void**) () from /usr/lib64/qt4/libQtCore.so.4
#3 0x00000038bd0b74f7 in ?? () from /usr/lib64/qt4/libQtNetwork.so.4
#4 0x00000038bd0a55c1 in ?? () from /usr/lib64/qt4/libQtNetwork.so.4
#5 0x0000003565bc7a24 in QApplicationPrivate::notify_helper(QObject*, QEvent*) () from /usr/lib64/qt4/libQtGui.so.4
#6 0x0000003565bcc50a in QApplication::notify(QObject*, QEvent*) () from /usr/lib64/qt4/libQtGui.so.4
#7 0x00000038bb15f483 in QCoreApplication::notifyInternal(QObject*, QEvent*) () from /usr/lib64/qt4/libQtCore.so.4
#8 0x00000038bb189458 in ?? () from /usr/lib64/qt4/libQtCore.so.4
#9 0x000000374c843bf2 in g_main_context_dispatch () from /usr/lib/libglib-2.0.so.0
#10 0x000000374c8443a0 in ?? () from /usr/lib/libglib-2.0.so.0
#11 0x000000374c84463d in g_main_context_iteration () from /usr/lib/libglib-2.0.so.0
#12 0x00000038bb189a7f in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib64/qt4/libQtCore.so.4
#13 0x0000003565c6b44e in ?? () from /usr/lib64/qt4/libQtGui.so.4
#14 0x00000038bb15e8a2 in QEventLoop::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib64/qt4/libQtCore.so.4
#15 0x00000038bb15eae4 in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib64/qt4/libQtCore.so.4
#16 0x00000038bb162e63 in QCoreApplication::exec() () from /usr/lib64/qt4/libQtCore.so.4
#17 0x0000000000407ba2 in main (argc=1, argv=0x7fffffffdc98) at ../plug/main.cpp:31

wysota
6th March 2011, 12:44
The backtrace doesn't indicate that you're within QMessageBox::exec(). It looks like the crash happens due to some networking operation. Are you using threads?

piorekf
6th March 2011, 12:48
I'm not using threads myself. Qt is using them. What I am doing is at the end of constructor calling check_for_updates() and I believe that because it is a network operation Qt is creating separate thread for it. This is bactrace from QtCreator:

Thread 2 (Thread 0x7ffff53ba700 (LWP 3449)):
#0 0x000000374940b9ab in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib/libpthread.so.0
No symbol table info available.
#1 0x00000038bb07a151 in QWaitCondition::wait(QMutex*, unsigned long) () from /usr/lib64/qt4/libQtCore.so.4
No symbol table info available.
#2 0x00000038bb06ecaf in ?? () from /usr/lib64/qt4/libQtCore.so.4
No symbol table info available.
#3 0x00000038bb079b15 in ?? () from /usr/lib64/qt4/libQtCore.so.4
No symbol table info available.
#4 0x0000003749406d4c in start_thread () from /lib/libpthread.so.0
No symbol table info available.
#5 0x00000037488d740d in clone () from /lib/libc.so.6
No symbol table info available.

Thread 1 (Thread 0x7ffff7fbc760 (LWP 3446)):
#0 0x00000038bd058192 in ?? () from /usr/lib64/qt4/libQtNetwork.so.4
No symbol table info available.
#1 0x00000038bd058bfc in ?? () from /usr/lib64/qt4/libQtNetwork.so.4
No symbol table info available.
#2 0x00000038bb173897 in QMetaObject::activate(QObject*, QMetaObject const*, int, void**) () from /usr/lib64/qt4/libQtCore.so.4
No symbol table info available.
#3 0x00000038bd0b74f7 in ?? () from /usr/lib64/qt4/libQtNetwork.so.4
No symbol table info available.
#4 0x00000038bd0a55c1 in ?? () from /usr/lib64/qt4/libQtNetwork.so.4
No symbol table info available.
#5 0x0000003565bc7a24 in QApplicationPrivate::notify_helper(QObject*, QEvent*) () from /usr/lib64/qt4/libQtGui.so.4
No symbol table info available.
#6 0x0000003565bcc50a in QApplication::notify(QObject*, QEvent*) () from /usr/lib64/qt4/libQtGui.so.4
No symbol table info available.
#7 0x00000038bb15f483 in QCoreApplication::notifyInternal(QObject*, QEvent*) () from /usr/lib64/qt4/libQtCore.so.4
No symbol table info available.
#8 0x00000038bb189458 in ?? () from /usr/lib64/qt4/libQtCore.so.4
No symbol table info available.
#9 0x000000374c843bf2 in g_main_context_dispatch () from /usr/lib/libglib-2.0.so.0
No symbol table info available.
#10 0x000000374c8443a0 in ?? () from /usr/lib/libglib-2.0.so.0
No symbol table info available.
#11 0x000000374c84463d in g_main_context_iteration () from /usr/lib/libglib-2.0.so.0
No symbol table info available.
#12 0x00000038bb189a7f in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib64/qt4/libQtCore.so.4
No symbol table info available.
#13 0x0000003565c6b44e in ?? () from /usr/lib64/qt4/libQtGui.so.4
No symbol table info available.
#14 0x00000038bb15e8a2 in QEventLoop::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib64/qt4/libQtCore.so.4
No symbol table info available.
#15 0x00000038bb15eae4 in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib64/qt4/libQtCore.so.4
No symbol table info available.
#16 0x00000038bb162e63 in QCoreApplication::exec() () from /usr/lib64/qt4/libQtCore.so.4
No symbol table info available.
#17 0x0000000000407ba2 in main (argc=1, argv=0x7fffffffe238) at ../plug/main.cpp:31
a = <incomplete type>
w = {<QMainWindow> = {<No data fields>}, ui = 0x69ced0, current_name = {d = 0x649940}, manual_check = false, amp_ops = 0x6d4ff0, amp = 0x78aa20, effect1 = 0x7c43a0, effect2 = 0x805db0, effect3 = 0x76c640, effect4 = 0x7ac260, about_window = 0x777550, save = 0x6d5de0, load = 0x761630, seffects = 0x7b8860, settings_win = 0x7c8840, saver = 0x788c30, reply = 0x967370}

wysota
6th March 2011, 14:56
Qt is not creating any threads for networking operations. What happens if you put a breakpoint just before the call to QMessageBox::exec() ? Or put a debug statement before and after exec() and see if it gets printed before the app crashes.

piorekf
6th March 2011, 16:01
If I add "qDebug() << "test"" before and after "msgbx->exec();" both are displayed. So this is not directly QMessageBox fault but occurs only when using exec() function (and QMessageBox::information static function).
I also checked and everything is working fine on Qt 4.7.1.

wysota
6th March 2011, 16:07
What's your application doing apart displaying the dialog? What happens if you change your connect statement to monitor for finished() rather than readyRead()?

piorekf
6th March 2011, 16:18
What's your application doing apart displaying the dialog?
Displaying main window of the program and nothing more. Like I said this function is called in the last line of the constructor.


What happens if you change your connect statement to monitor for finished() rather than readyRead()?
It works fine when I change it to finished(). Can you please explain this? I took this from Qt's Networking -> HTTP client example.

wysota
6th March 2011, 18:07
I suspect readyRead() is emitted a couple of times and it causes some problems with your code being called multiple times. finished() is a proper way of handling your situation anyway.

piorekf
6th March 2011, 18:11
OK, thank you for help.