Results 1 to 11 of 11

Thread: QMessabeBox cause Segmentation Fault

  1. #1
    Join Date
    Mar 2011
    Location
    Poland
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Maemo/MeeGo

    Default QMessabeBox cause Segmentation Fault

    I have following code:
    Qt Code:
    1. void MainWindow::check_for_updates()
    2. {
    3. QNetworkAccessManager *qnam = new QNetworkAccessManager(this);
    4. reply = qnam->get(QNetworkRequest((QUrl)"http://piorekf.org/plug/VERSION"));
    5. connect(reply, SIGNAL(readyRead()), this, SLOT(httpReadyRead()));
    6. }
    7.  
    8. void MainWindow::httpReadyRead()
    9. {
    10. if(reply->readAll() > VERSION)
    11. {
    12. QLabel *label = new QLabel(tr("<b>Update available!</b>"), this);
    13. ui->statusBar->addWidget(label);
    14. QMessageBox *msgbx = new QMessageBox;
    15. msgbx->setWindowTitle(tr("Update"));
    16. msgbx->setText(tr("<b>Update available!</b>"));
    17. msgbx->setInformativeText(tr("Check homepage for new version"));
    18. msgbx->setIcon(QMessageBox::Information);
    19. msgbx->show();
    20. // QMessageBox::information(this, "Update", "<b>Update available!</b><br>Check homepage for new version.");
    21. }
    22. else
    23. ui->statusBar->showMessage(tr("You are using the newest version"), 5000);
    24. }
    To copy to clipboard, switch view to plain text mode 

    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?

  2. #2
    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: QMessabeBox cause Segmentation Fault

    Please post a backtrace of the crash.
    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.


  3. #3
    Join Date
    Mar 2011
    Location
    Poland
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Maemo/MeeGo

    Default Re: QMessabeBox cause Segmentation Fault

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

  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: QMessabeBox cause Segmentation Fault

    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?
    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
    Mar 2011
    Location
    Poland
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Maemo/MeeGo

    Default Re: QMessabeBox cause Segmentation Fault

    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:
    Qt Code:
    1. Thread 2 (Thread 0x7ffff53ba700 (LWP 3449)):
    2. #0 0x000000374940b9ab in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib/libpthread.so.0
    3. No symbol table info available.
    4. #1 0x00000038bb07a151 in QWaitCondition::wait(QMutex*, unsigned long) () from /usr/lib64/qt4/libQtCore.so.4
    5. No symbol table info available.
    6. #2 0x00000038bb06ecaf in ?? () from /usr/lib64/qt4/libQtCore.so.4
    7. No symbol table info available.
    8. #3 0x00000038bb079b15 in ?? () from /usr/lib64/qt4/libQtCore.so.4
    9. No symbol table info available.
    10. #4 0x0000003749406d4c in start_thread () from /lib/libpthread.so.0
    11. No symbol table info available.
    12. #5 0x00000037488d740d in clone () from /lib/libc.so.6
    13. No symbol table info available.
    14.  
    15. Thread 1 (Thread 0x7ffff7fbc760 (LWP 3446)):
    16. #0 0x00000038bd058192 in ?? () from /usr/lib64/qt4/libQtNetwork.so.4
    17. No symbol table info available.
    18. #1 0x00000038bd058bfc in ?? () from /usr/lib64/qt4/libQtNetwork.so.4
    19. No symbol table info available.
    20. #2 0x00000038bb173897 in QMetaObject::activate(QObject*, QMetaObject const*, int, void**) () from /usr/lib64/qt4/libQtCore.so.4
    21. No symbol table info available.
    22. #3 0x00000038bd0b74f7 in ?? () from /usr/lib64/qt4/libQtNetwork.so.4
    23. No symbol table info available.
    24. #4 0x00000038bd0a55c1 in ?? () from /usr/lib64/qt4/libQtNetwork.so.4
    25. No symbol table info available.
    26. #5 0x0000003565bc7a24 in QApplicationPrivate::notify_helper(QObject*, QEvent*) () from /usr/lib64/qt4/libQtGui.so.4
    27. No symbol table info available.
    28. #6 0x0000003565bcc50a in QApplication::notify(QObject*, QEvent*) () from /usr/lib64/qt4/libQtGui.so.4
    29. No symbol table info available.
    30. #7 0x00000038bb15f483 in QCoreApplication::notifyInternal(QObject*, QEvent*) () from /usr/lib64/qt4/libQtCore.so.4
    31. No symbol table info available.
    32. #8 0x00000038bb189458 in ?? () from /usr/lib64/qt4/libQtCore.so.4
    33. No symbol table info available.
    34. #9 0x000000374c843bf2 in g_main_context_dispatch () from /usr/lib/libglib-2.0.so.0
    35. No symbol table info available.
    36. #10 0x000000374c8443a0 in ?? () from /usr/lib/libglib-2.0.so.0
    37. No symbol table info available.
    38. #11 0x000000374c84463d in g_main_context_iteration () from /usr/lib/libglib-2.0.so.0
    39. No symbol table info available.
    40. #12 0x00000038bb189a7f in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib64/qt4/libQtCore.so.4
    41. No symbol table info available.
    42. #13 0x0000003565c6b44e in ?? () from /usr/lib64/qt4/libQtGui.so.4
    43. No symbol table info available.
    44. #14 0x00000038bb15e8a2 in QEventLoop::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib64/qt4/libQtCore.so.4
    45. No symbol table info available.
    46. #15 0x00000038bb15eae4 in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib64/qt4/libQtCore.so.4
    47. No symbol table info available.
    48. #16 0x00000038bb162e63 in QCoreApplication::exec() () from /usr/lib64/qt4/libQtCore.so.4
    49. No symbol table info available.
    50. #17 0x0000000000407ba2 in main (argc=1, argv=0x7fffffffe238) at ../plug/main.cpp:31
    51. a = <incomplete type>
    52. 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}
    To copy to clipboard, switch view to plain text mode 
    Last edited by piorekf; 6th March 2011 at 12:53.

  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: QMessabeBox cause Segmentation Fault

    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.
    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
    Mar 2011
    Location
    Poland
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Maemo/MeeGo

    Default Re: QMessabeBox cause Segmentation Fault

    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.

  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: QMessabeBox cause Segmentation Fault

    What's your application doing apart displaying the dialog? What happens if you change your connect statement to monitor for finished() rather than readyRead()?
    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
    Mar 2011
    Location
    Poland
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Maemo/MeeGo

    Default Re: QMessabeBox cause Segmentation Fault

    Quote Originally Posted by wysota View Post
    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.

    Quote Originally Posted by wysota View Post
    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.

  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: QMessabeBox cause Segmentation Fault

    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.
    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
    Mar 2011
    Location
    Poland
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Maemo/MeeGo

    Default Re: QMessabeBox cause Segmentation Fault

    OK, thank you for help.

Similar Threads

  1. segmentation fault
    By dreamer in forum Qt Programming
    Replies: 6
    Last Post: 9th May 2008, 07:48
  2. Segmentation Fault?!
    By r07f1 in forum Newbie
    Replies: 2
    Last Post: 11th April 2008, 15:10
  3. segmentation fault
    By mattia in forum Newbie
    Replies: 22
    Last Post: 7th November 2007, 10:37
  4. Segmentation Fault
    By merry in forum General Programming
    Replies: 4
    Last Post: 12th March 2007, 04:08
  5. (Another) segmentation fault
    By Lebowski in forum Qt Programming
    Replies: 27
    Last Post: 6th April 2006, 06: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.