PDA

View Full Version : segfault on qtextstream



patcito
25th February 2006, 03:34
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:


QFile invoice("cutePOSinvoice.html");
if (!invoice.open(QIODevice::ReadOnly | QIODevice::Text))
return;

QTextStream in(&invoice);
QString templateoutput = in.readAll();

qDebug() << templateoutput;
invoice.close();
QString clientIDinvoice = getAccountID();

templateoutput.replace (QString("$ClientID"),clientIDinvoice );
QFile data("output.html");
if (data.open(QFile::WriteOnly)) {
QTextStream out(&data);
out << templateoutput;
}

jacek
25th February 2006, 15:22
Could you post the backtrace?

patcito
25th February 2006, 18:18
Sure, here it is:

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

jacek
25th February 2006, 18:26
Did you compile your application in debug mode?

patcito
25th February 2006, 18:27
Did you compile your application in debug mode?
how can I do so?

patcito
25th February 2006, 18:36
ok I get this now:


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

patcito
25th February 2006, 18:46
OK it's working now :) , I changed

QString clientIDinvoice = getAccountID();
to

QString clientIDinvoice;
clientIDinvoice.append(getAccountID());

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

jacek
25th February 2006, 19:22
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?

patcito
26th February 2006, 01:08
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

jacek
26th February 2006, 01:26
What does getAccountID() do?

patcito
26th February 2006, 03:22
What does getAccountID() do?

it returns a QString

jacek
26th February 2006, 03:29
it returns a QString
Either there is something wrong with this function or there is a bug in Qt. Could you post its code (just the part that constructs that string)?

patcito
26th February 2006, 03:46
Either there is something wrong with this function or there is a bug in Qt. Could you post its code (just the part that constructs that string)?
here it is:


QString GenerateInvoiceDialog::getAccountID(){
QString clientvarIDstr;
clientvarIDstr.setNum(clientvarID);
return clientvarIDstr;
}


update: clientvarID is an int class var, by the way I also get the same error with this function:


QString GenerateInvoiceDialog::getCustomerName(){

QString clientname = ui.clientnamelabel->text();
return clientname;
}

jacek
26th February 2006, 14:10
This is really strange. What compiler do you use? Do you use the Qt 4.1.1 or its snapshot?