Results 1 to 14 of 14

Thread: segfault on qtextstream

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Posts
    46
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    13

    Default need help to write text to a file

    hey all,
    First I open a file "cutePOSinvoice.html" that I read with
    QTextStream, then I put the content in a QString "templateoutput ". I
    replace some text in templateoutput with some other string and then
    create a new file "output.html" to write the new templateoutput string
    into. Everything works fine except the writing cause when I remove it the app doesn't crash, it might be due to something else but I'm pretty clueless. Any idea what
    I'm doing wrong? thanx in advance, here is the code:
    Qt Code:
    1. QFile invoice("cutePOSinvoice.html");
    2. if (!invoice.open(QIODevice::ReadOnly | QIODevice::Text))
    3. return;
    4.  
    5. QTextStream in(&invoice);
    6. QString templateoutput = in.readAll();
    7.  
    8. qDebug() << templateoutput;
    9. invoice.close();
    10. QString clientIDinvoice = getAccountID();
    11.  
    12. templateoutput.replace (QString("$ClientID"),clientIDinvoice );
    13. QFile data("output.html");
    14. if (data.open(QFile::WriteOnly)) {
    15. QTextStream out(&data);
    16. out << templateoutput;
    17. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by patcito; 25th February 2006 at 05:41.

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

    Default Re: segfault on qtextstream

    Could you post the backtrace?

  3. #3
    Join Date
    Jan 2006
    Posts
    46
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    13

    Default Re: segfault on qtextstream

    Sure, here it is:
    Qt Code:
    1. Program received signal SIGSEGV, Segmentation fault.
    2. [Switching to Thread 925652672 (LWP 21692)]
    3. 0x375792ea in QReadWriteLock::lockForRead (this=0xe959000) at thread/qreadwritelock.cpp:127
    4. 127 QMutexLocker lock(&d->mutex);
    5. (gdb) bt
    6. #0 0x375792ea in QReadWriteLock::lockForRead (this=0xe959000) at thread/qreadwritelock.cpp:127
    7. #1 0x37639758 in QMetaObject::activate (sender=0x2084f837, from_signal_index=6408, to_signal_index=6656, argv=0xc1bdcc00)
    8. at kernel/qobject.cpp:2690
    9. #2 0x6398903f in ?? ()
    10. #3 0x2084f837 in ?? ()
    11. #4 0x00001908 in ?? ()
    12. #5 0x00001a00 in ?? ()
    13. #6 0xc1bdcc00 in ?? ()
    14. #7 0xecd0003f in ?? ()
    15. #8 0x8f477837 in ?? ()
    16. #9 0xc1bdc037 in ?? ()
    17. #10 0xf16bf63f in ?? ()
    18. #11 0x00001737 in ?? ()
    19. #12 0xeb9d3400 in ?? ()
    20. #13 0xc1bdd837 in ?? ()
    21. #14 0xdbf8783f in ?? ()
    22. #15 0x2084f837 in ?? ()
    23. #16 0xeb8e9008 in ?? ()
    24. #17 0x00000237 in ?? ()
    25. #18 0x00000300 in ?? ()
    26. #19 0xc1bdcc00 in ?? ()
    27. #20 0xeb9d343f in ?? ()
    28. #21 0xc1c9e837 in ?? ()
    29. #22 0x00000137 in ?? ()
    30. #23 0xc1be0000 in ?? ()
    31. #24 0xf16b303f in ?? ()
    32. #25 0x0e95a837 in ?? ()
    33. #26 0x00000008 in ?? ()
    34. Cannot access memory at address 0xc1bd983b
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: segfault on qtextstream

    Did you compile your application in debug mode?

  5. #5
    Join Date
    Jan 2006
    Posts
    46
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    13

    Default Re: segfault on qtextstream

    Quote Originally Posted by jacek
    Did you compile your application in debug mode?
    how can I do so?

  6. #6
    Join Date
    Jan 2006
    Posts
    46
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    13

    Default Re: segfault on qtextstream

    ok I get this now:
    Qt Code:
    1. Program received signal SIGSEGV, Segmentation fault.
    2. [Switching to Thread 925624000 (LWP 22007)]
    3. 0x3756fb0a in q_atomic_increment (ptr=0x375720dd) at qatomic.h:68
    4. 68 qatomic.h: No such file or directory.
    5. in qatomic.h
    6. (gdb) bt
    7. #0 0x3756fb0a in q_atomic_increment (ptr=0x375720dd) at qatomic.h:68
    8. #1 0x3756fb4f in QBasicAtomic::ref (this=0x375720dd) at qatomic.h:70
    9. #2 0x375713b1 in QString (this=0x3fa168f4, s=@0x3fa169ac) at qstring.h:568
    10. #3 0x375b70a4 in QString::replace (this=0x3fa169c8, before=@0x3fa169f8, after=@0x3fa169ac, cs=Qt::CaseSensitive)
    11. at tools/qstring.cpp:1504
    12. #4 0x0806bc5c in GenerateInvoiceDialog::on_saveandPrintpushButton_clicked (this=0x3fa17be0) at generateinvoice.cpp:552
    13. #5 0x080adf09 in GenerateInvoiceDialog::qt_metacall (this=0x3fa17be0, _c=QMetaObject::InvokeMetaMethod, _id=12,
    14. _a=0x3fa16f4c) at moc_generateinvoice.cpp:96
    15. #6 0x376326c3 in QMetaObject::activate (sender=0x82076d8, from_signal_index=25, to_signal_index=26, argv=0x3fa16f4c)
    16. at kernel/qobject.cpp:2678
    17. #7 0x37632890 in QMetaObject::activate (sender=0x82076d8, m=0x37eb1e90, from_local_signal_index=2, to_local_signal_index=3,
    18. argv=0x3fa16f4c) at kernel/qobject.cpp:2725
    19. #8 0x37db8878 in QAbstractButton::clicked (this=0x82076d8, _t1=false) at .moc/debug-shared/moc_qabstractbutton.cpp:170
    20. #9 0x37c16674 in QAbstractButtonPrivate::click (this=0x82076f0) at widgets/qabstractbutton.cpp:477
    21. #10 0x37c16960 in QAbstractButton::mouseReleaseEvent (this=0x82076d8, e=0x3fa175f4) at widgets/qabstractbutton.cpp:957
    22. #11 0x379e559f in QWidget::event (this=0x82076d8, event=0x3fa175f4) at kernel/qwidget.cpp:4938
    23. #12 0x37c15b98 in QAbstractButton::event (this=0x82076d8, e=0x3fa175f4) at widgets/qabstractbutton.cpp:925
    24. #13 0x37c91940 in QPushButton::event (this=0x82076d8, e=0x3fa175f4) at widgets/qpushbutton.cpp:562
    25. #14 0x3799216b in QApplicationPrivate::notify_helper (this=0x80c90f0, receiver=0x82076d8, e=0x3fa175f4)
    26. at kernel/qapplication.cpp:3137
    27. #15 0x37992c3e in QApplication::notify (this=0x3fa19100, receiver=0x82076d8, e=0x3fa175f4) at kernel/qapplication.cpp:2867
    28. #16 0x3799afe7 in QCoreApplication::sendSpontaneousEvent (receiver=0x82076d8, event=0x3fa175f4) at qcoreapplication.h:174
    29. #17 0x37a00c14 in QETWidget::translateMouseEvent (this=0x82076d8, event=0x3fa17a70) at kernel/qapplication_x11.cpp:3576
    30. #18 0x379fe98c in QApplication::x11ProcessEvent (this=0x3fa19100, event=0x3fa17a70) at kernel/qapplication_x11.cpp:2701
    31. #19 0x37a12e04 in QEventDispatcherX11::processEvents (this=0x80cd9b0, flags=@0x3fa17b14)
    32. at kernel/qeventdispatcher_x11.cpp:112
    33. #20 0x3761b579 in QEventLoop::processEvents (this=0x3fa17b98, flags=@0x3fa17b4c) at kernel/qeventloop.cpp:124
    34. #21 0x3761b7fb in QEventLoop::exec (this=0x3fa17b98, flags=@0x3fa17ba0) at kernel/qeventloop.cpp:164
    35. #22 0x37d0c450 in QDialog::exec (this=0x3fa17be0) at dialogs/qdialog.cpp:387
    36. #23 0x08050b81 in CutePOS::on_invoicestableView_doubleClicked (this=0x8139268, index=@0x81e85c8) at cutepos.cpp:531
    37. #24 0x080ad28b in CutePOS::qt_metacall (this=0x8139268, _c=QMetaObject::InvokeMetaMethod, _id=6, _a=0x3fa1824c)
    38. at moc_cutepos.cpp:92
    39. #25 0x376326c3 in QMetaObject::activate (sender=0x8145218, from_signal_index=28, to_signal_index=28, argv=0x3fa1824c)
    40. at kernel/qobject.cpp:2678
    41. #26 0x37633472 in QMetaObject::activate (sender=0x8145218, m=0x37eb1b60, local_signal_index=2, argv=0x3fa1824c)
    42. at kernel/qobject.cpp:2716
    43. #27 0x37d3645e in QAbstractItemView::doubleClicked (this=0x8145218, _t1=@0x81e85c8) at moc_qabstractitemview.cpp:264
    44. #28 0x37d364e6 in QAbstractItemView::mouseDoubleClickEvent (this=0x8145218, event=0x3fa18ae4)
    45. ---Type <return> to continue, or q <return> to quit---
    46. at itemviews/qabstractitemview.cpp:1127
    47. #29 0x379e55bd in QWidget::event (this=0x8145218, event=0x3fa18ae4) at kernel/qwidget.cpp:4942
    48. #30 0x37c4d55a in QFrame::event (this=0x8145218, e=0x3fa18ae4) at widgets/qframe.cpp:609
    49. #31 0x37cd6e8b in QAbstractScrollArea::viewportEvent (this=0x8145218, e=0x3fa18ae4) at widgets/qabstractscrollarea.cpp:472
    50. #32 0x37d361f3 in QAbstractItemView::viewportEvent (this=0x8145218, event=0x3fa18ae4) at itemviews/qabstractitemview.cpp:952
    51. #33 0x37cd7729 in QAbstractScrollAreaPrivate::viewportEvent (this=0x8151bc0, e=0x3fa18ae4)
    52. at widgets/qabstractscrollarea.cpp:93
    53. #34 0x37cd76ad in QAbstractScrollAreaViewport::event (this=0x813ff30, e=0x3fa18ae4) at widgets/qabstractscrollarea.cpp:105
    54. #35 0x3799216b in QApplicationPrivate::notify_helper (this=0x80c90f0, receiver=0x813ff30, e=0x3fa18ae4)
    55. at kernel/qapplication.cpp:3137
    56. #36 0x37992c3e in QApplication::notify (this=0x3fa19100, receiver=0x813ff30, e=0x3fa18ae4) at kernel/qapplication.cpp:2867
    57. #37 0x3799afe7 in QCoreApplication::sendSpontaneousEvent (receiver=0x813ff30, event=0x3fa18ae4) at qcoreapplication.h:174
    58. #38 0x37a00c14 in QETWidget::translateMouseEvent (this=0x813ff30, event=0x3fa18f60) at kernel/qapplication_x11.cpp:3576
    59. #39 0x379fe98c in QApplication::x11ProcessEvent (this=0x3fa19100, event=0x3fa18f60) at kernel/qapplication_x11.cpp:2701
    60. #40 0x37a12e04 in QEventDispatcherX11::processEvents (this=0x80cd9b0, flags=@0x3fa19004)
    61. at kernel/qeventdispatcher_x11.cpp:112
    62. #41 0x3761b579 in QEventLoop::processEvents (this=0x3fa19088, flags=@0x3fa1903c) at kernel/qeventloop.cpp:124
    63. #42 0x3761b7fb in QEventLoop::exec (this=0x3fa19088, flags=@0x3fa19090) at kernel/qeventloop.cpp:164
    64. #43 0x37621722 in QCoreApplication::exec () at kernel/qcoreapplication.cpp:662
    65. #44 0x37991798 in QApplication::exec () at kernel/qapplication.cpp:2682
    66. #45 0x0804e16d in main (argc=1, argv=0x3fa191b4) at main.cpp:44
    To copy to clipboard, switch view to plain text mode 

  7. #7
    Join Date
    Jan 2006
    Posts
    46
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    13

    Thumbs up Re: segfault on qtextstream

    OK it's working now , I changed
    Qt Code:
    1. QString clientIDinvoice = getAccountID();
    To copy to clipboard, switch view to plain text mode 
    to
    Qt Code:
    1. QString clientIDinvoice;
    2. clientIDinvoice.append(getAccountID());
    To copy to clipboard, switch view to plain text mode 

    thanx for your help.
    any idea why it was causing a segfault by the way?

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

    Default Re: segfault on qtextstream

    Quote Originally Posted by patcito
    any idea why it was causing a segfault by the way?
    It might be a Qt bug. Which Qt version do you use? Do you use threads?

  9. #9
    Join Date
    Jan 2006
    Posts
    46
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    13

    Default Re: segfault on qtextstream

    Quote Originally Posted by jacek
    It might be a Qt bug. Which Qt version do you use? Do you use threads?
    No I'm not using threads and I'm using 4.1.1

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

    Default Re: segfault on qtextstream

    What does getAccountID() do?

  11. #11
    Join Date
    Jan 2006
    Posts
    46
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    13

    Default Re: segfault on qtextstream

    Quote Originally Posted by jacek
    What does getAccountID() do?
    it returns a QString

Similar Threads

  1. Segfault in Construkctor of QCoreApplication?!?
    By schulze in forum Qt Programming
    Replies: 1
    Last Post: 6th November 2008, 12:50
  2. when close QTextStream
    By mattia in forum Newbie
    Replies: 1
    Last Post: 24th November 2007, 14:17
  3. QTextStream + QFile issue
    By trueneo in forum Qt Programming
    Replies: 3
    Last Post: 22nd September 2007, 16:16
  4. Create QTextStream
    By Morea in forum Qt Programming
    Replies: 1
    Last Post: 17th June 2007, 21:25
  5. reading from QTextStream
    By matyi52 in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 14th December 2006, 08:26

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
  •  
Qt is a trademark of The Qt Company.