Results 1 to 7 of 7

Thread: http trouble again, segfaults when no internet

  1. #1
    Join Date
    Jan 2006
    Location
    N.B. Canada
    Posts
    47
    Thanked 8 Times in 7 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default http trouble again, segfaults when no internet

    Hello, hopefully someone can help me out, and show me where I am making a mistake. I have attached a simple application that I am using to test two classes, Image and Document. Although in this example, it isn't totally representative of how classes are used, the http part and functionality is very much similar to how it is in real code. As well the API is somewhat similar to the real code, ie. Its one-time use classes that delete themselves upon finishing the job. The Image class is used to download an image from a web server. Document is used to get a html or xml, or any other type of document from a web server. You supply a url in the line edit, and press 1 of the two buttons. Get Image button gets the image, and then displays it in the top. Get Document button gets the document and puts it in the text edit in the bottom. The 2 http functionalities in the 2 classes are almost identical. The test works fine, except that it crashes when there is no internet connection. For example if I phisically remove the cable from my cable modem, and try to run this, it crashes. I am not sure exactly where the problem is. backtrace doesn't seem to provide much useful info, at least not to me. And I am not sure what else to try. Any ideas are welcome.

    Bojan
    Attached Files Attached Files
    The march of progress:
    C:
    printf("%10.2f", x);
    C++:
    cout << setw(10) << setprecision(2) << showpoint << x;
    Java:
    java.text.NumberFormat formatter = java.text.NumberFormat.getNumberInstance();
    formatter.setMinimumFractionDigits(2);
    formatter.setMaximumFractionDigits(2);
    String s = formatter.format(x);
    for (int i = s.length(); i < 10; i++) System.out.print(' ');
    System.out.print(s);

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: http trouble again, segfaults when no internet

    Try to debug the application and see where it crashes.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 975 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: http trouble again, segfaults when no internet

    Quote Originally Posted by Bojan
    backtrace doesn't seem to provide much useful info
    Could you post it here?

  4. #4
    Join Date
    Jan 2006
    Posts
    46
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: http trouble again, segfaults when no internet

    It seems like you're deleting some wrong pointer. But I'm just guessing. I haven't tried your code without connection yet, and haven't looked the code deeply neither but, maybe you should take a closer look at Image::httpDone(bool) slot where you're deleting objects.
    Anyways, I agrre with Wysota, you should run your app with gdb and see where it crashes.

    Cheers.
    Kandalf
    There's no place like ~

  5. #5
    Join Date
    Jan 2006
    Location
    Paris, France
    Posts
    227
    Thanks
    3
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: http trouble again, segfaults when no internet

    Hello,

    I tested on a Linux Debian, and here is the backtrace from gdb:

    Qt Code:
    1. Program received signal SIGSEGV, Segmentation fault.
    2. [Switching to Thread -1220528448 (LWP 8604)]
    3. 0xb79b009d in QMetaObject::activate () from /usr/lib/libQtCore_debug.so.4
    4. (gdb) where
    5. #0 0xb79b009d in QMetaObject::activate () from /usr/lib/libQtCore_debug.so.4
    6. #1 0xb79b0a2c in QMetaObject::activate () from /usr/lib/libQtCore_debug.so.4
    7. #2 0xb7a4e171 in QHttp::stateChanged () from /usr/lib/libQtNetwork_debug.so.4
    8. #3 0xb7a4e22a in QHttpPrivate::setState () from /usr/lib/libQtNetwork_debug.so.4
    9. #4 0xb7a4edfd in QHttpPrivate::closeConn () from /usr/lib/libQtNetwork_debug.so.4
    10. #5 0xb7a56f68 in QHttpPrivate::slotError () from /usr/lib/libQtNetwork_debug.so.4
    11. #6 0xb7a592a9 in QHttp::qt_metacall () from /usr/lib/libQtNetwork_debug.so.4
    12. #7 0xb79b05b1 in QMetaObject::activate () from /usr/lib/libQtCore_debug.so.4
    13. #8 0xb79b0a2c in QMetaObject::activate () from /usr/lib/libQtCore_debug.so.4
    14. #9 0xb7a68e94 in QAbstractSocket::error () from /usr/lib/libQtNetwork_debug.so.4
    15. #10 0xb7a6b244 in QAbstractSocketPrivate::startConnecting () from /usr/lib/libQtNetwork_debug.so.4
    16. #11 0xb7a6c859 in QAbstractSocket::qt_metacall () from /usr/lib/libQtNetwork_debug.so.4
    17. #12 0xb7a770f2 in QTcpSocket::qt_metacall () from /usr/lib/libQtNetwork_debug.so.4
    18. #13 0xb79af815 in QObject::event () from /usr/lib/libQtCore_debug.so.4
    19. #14 0xb7b4d8b4 in QApplicationPrivate::notify_helper () from /usr/lib/libQtGui_debug.so.4
    20. #15 0xb7b4e8c9 in QApplication::notify () from /usr/lib/libQtGui_debug.so.4
    21. #16 0xb79a444d in QCoreApplication::sendPostedEvents () from /usr/lib/libQtCore_debug.so.4
    22. #17 0xb7bb5711 in QEventDispatcherX11::processEvents () from /usr/lib/libQtGui_debug.so.4
    23. #18 0xb79a1a24 in QEventLoop::processEvents () from /usr/lib/libQtCore_debug.so.4
    24. #19 0xb79a1c76 in QEventLoop::exec () from /usr/lib/libQtCore_debug.so.4
    25. #20 0xb79a4611 in QCoreApplication::exec () from /usr/lib/libQtCore_debug.so.4
    26. #21 0xb7b4d5d7 in QApplication::exec () from /usr/lib/libQtGui_debug.so.4
    27. #22 0x0804d0a3 in main (argc=1, argv=0xbfee1394) at imgtestdialog.cpp:216
    To copy to clipboard, switch view to plain text mode 

    That doesn't help a lot...

    Guilugi.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 975 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: http trouble again, segfaults when no internet

    I think that the problem is with:
    Qt Code:
    1. delete http;
    2. http = 0;
    To copy to clipboard, switch view to plain text mode 
    It looks like you delete it while there are still some unprocessed events. Since you call Image::deleteLater(), you could omit those two lines.

  7. #7
    Join Date
    Jan 2006
    Location
    N.B. Canada
    Posts
    47
    Thanked 8 Times in 7 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: http trouble again, segfaults when no internet

    Sorry, i was sick with the flu or cold yesturday so haven't been using the computer. Anyway it looks like you guys solved the problem for me. Indeed if I comment out the delete http lines the code works fine. Kinda weird, didn't really think that could be the problem. Should have tried that maybe before posting I guess. thanks all.

    Bojan
    The march of progress:
    C:
    printf("%10.2f", x);
    C++:
    cout << setw(10) << setprecision(2) << showpoint << x;
    Java:
    java.text.NumberFormat formatter = java.text.NumberFormat.getNumberInstance();
    formatter.setMinimumFractionDigits(2);
    formatter.setMaximumFractionDigits(2);
    String s = formatter.format(x);
    for (int i = s.length(); i < 10; i++) System.out.print(' ');
    System.out.print(s);

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.