PDA

View Full Version : QT4.2 corrupted double-linked list and QRadioButton existance



mtrpoland
19th July 2007, 10:35
Hi again,
I have encountered an odd obstacle.
I implement MVC pattern using subclassed QTreeView as myView and QAbstractItemModel as myModel. I place the myView object in MyMVC that contains combo box and line edit, which are used as filter input. Anyway, everything works perfect with the whole application.

But when I add a few (commented below in mymvc.cpp) lines I get Core Dumped and the main window of my program just shows for a while and dissapears.

Above the backtrace I receive:
*** glibc detected *** ./PL09: corrupted double-linked list: 0x08124aa8 ***
(PL09 is a name of a application file)

Here is the code of mymvc.h


#ifndef MTR_SAFETY_DECLARATION_FOR_MYMVC_H
#define MTR_SAFETY_DECLARATION_FOR_MYMVC_H
#include <QWidget>
namespace MTR {
class Book;
class SBook;
}
class myView;
class myModel;
class QGridLayout;
class QLabel;
class QComboBox;
class QLineEdit;
class QRadioButton;

class MyMVC : public QWidget {
Q_OBJECT
public:
MyMVC(QList<MTR::Book>* list = 0, QWidget* parent = 0);
void prodModel(QList<MTR::Book>*);
public slots:
bool getCaseSensitive(void) { return caseSensitive; }
void setCaseSensitive(bool cs) { caseSensitive = cs; }
signals:
void doubleClickInTreeView(int);
private:
QList<MTR::SBook>* slist;
QLineEdit* le;
QComboBox* qcb;
myModel* model;
myView* qtv;
QGridLayout* qvb;
QLabel* label;
bool caseSensitive;
QRadioButton* radioOne;
QRadioButton* radioTwo;
};

#endif



Then you have mymvc.cpp


#include "mymvc.h"
#include "myView.h"
#include "sbook.h"
#include "myModel.h"
#include "myHeaderView.h"
#include <QList>
#include <QGridLayout>
#include <QLabel>
#include <QLineEdit>
#include <QComboBox>
#include <QRadioButton>

MyMVC::MyMVC(QList<MTR::Book>* list, QWidget* parent) {
slist = new QList<MTR::SBook>();
for(int i = 0;i<list->size();++i) {
slist->append(MTR::SBook(i,list->value(i)));
}
setFixedSize(590,400);

le = new QLineEdit();
qcb = new QComboBox();
qcb->addItem(tr("filter by Title"));
qcb->addItem(tr("filter by Author"));
qcb->addItem(tr("filter by Publisher"));
qcb->setCurrentIndex(0);

model = new myModel(*slist,le,qcb);
model->filter();

qtv = new myView(model);
qtv->header()->setSortIndicator(0,Qt::DescendingOrder);

label = new QLabel(tr("Enter a character string below"));
//radioOne = new QRadioButton(tr("Case Sensitive - TRUE"));
//radioTwo = new QRadioButton(tr("Case Sensitive - FALSE"));
//radioOne->setChecked(true);
caseSensitive = true;
qvb = new QGridLayout();
//connect(radioOne,SIGNAL(toggled(bool)),this,SLOT(s etCaseSensitive(bool)));
connect(qcb,SIGNAL(currentIndexChanged(int)),le,SL OT(clear()));
connect(qcb,SIGNAL(currentIndexChanged(int)),qtv,S LOT(filter()));
connect(le,SIGNAL(textChanged(const QString &)),qtv,SLOT(filter()));
connect(model,SIGNAL(fromTVtoVM(int)),this,SIGNAL( doubleClickInTreeView(int)));

qvb->addWidget(label,0,0);
//qvb->addWidget(radioOne,0,1);
qvb->addWidget(le,1,0);
//qvb->addWidget(radioTwo,1,1);
qvb->addWidget(qcb,2,0,1,2);
qvb->addWidget(qtv,3,0,1,2);
setLayout(qvb);
}

void MyMVC::prodModel(QList<MTR::Book>* list) {
slist->clear();
for(int i = 0;i<list->size();++i) {
slist->append(MTR::SBook(i,list->value(i)));
}
model->setInternalList(*slist);
qcb->setCurrentIndex(0);
qtv->filter();

}



So my question is simple: what is going on... ?

jpn
19th July 2007, 12:39
Could you paste backtrace from debugger?

mtrpoland
19th July 2007, 12:54
Aye, here you have:


======= Backtrace: =========
/lib/tls/i686/cmov/libc.so.6[0xb72a6ceb]
/lib/tls/i686/cmov/libc.so.6[0xb72a8ecd]
/lib/tls/i686/cmov/libc.so.6(malloc+0x7f)[0xb72aa83f]
/lib/tls/i686/cmov/libc.so.6[0xb7258c79]
/lib/tls/i686/cmov/libc.so.6(iconv_open+0x1aa)[0xb725870a]
/usr/local/Trolltech/Qt-4.2.3/lib/libQtCore.so.4[0xb7656094]
/usr/local/Trolltech/Qt-4.2.3/lib/libQtCore.so.4[0xb76568d7]
/usr/local/Trolltech/Qt-4.2.3/lib/libQtCore.so.4(_ZN7QString13fromLocal8BitEPKci+0x6 a)[0xb75b395a]
/usr/local/Trolltech/Qt-4.2.3/lib/libQtCore.so.4(_ZN16QCoreApplication9argumentsEv+0 x73)[0xb762a2e3]
/usr/local/Trolltech/Qt-4.2.3/lib/libQtGui.so.4[0xb79fae7d]
/usr/local/Trolltech/Qt-4.2.3/lib/libQtGui.so.4[0xb79fbad6]
/usr/lib/libSM.so.6(_SmcProcessMessage+0xe3c)[0xb7876924]
/usr/lib/libICE.so.6(IceProcessMessages+0x3c0)[0xb78694c6]
/usr/local/Trolltech/Qt-4.2.3/lib/libQtGui.so.4[0xb79f48f8]
/usr/local/Trolltech/Qt-4.2.3/lib/libQtGui.so.4[0xb79f4977]
/usr/local/Trolltech/Qt-4.2.3/lib/libQtCore.so.4(_ZN11QMetaObject8activateEP7QObject iiPPv+0x688)[0xb7639908]
/usr/local/Trolltech/Qt-4.2.3/lib/libQtCore.so.4(_ZN11QMetaObject8activateEP7QObject PKS_iPPv+0x3a)[0xb763a28a]
/usr/local/Trolltech/Qt-4.2.3/lib/libQtCore.so.4(_ZN15QSocketNotifier9activatedEi+0x 43)[0xb7658f03]
/usr/local/Trolltech/Qt-4.2.3/lib/libQtCore.so.4(_ZN15QSocketNotifier5eventEP6QEvent +0x24f)[0xb76409af]
/usr/local/Trolltech/Qt-4.2.3/lib/libQtGui.so.4(_ZN19QApplicationPrivate13notify_hel perEP7QObjectP6QEvent+0x180)[0xb79a7230]
/usr/local/Trolltech/Qt-4.2.3/lib/libQtGui.so.4(_ZN12QApplication6notifyEP7QObjectP6 QEvent+0x111)[0xb79a9961]
/usr/local/Trolltech/Qt-4.2.3/lib/libQtCore.so.4[0xb764b51f]
/usr/lib/libglib-2.0.so.0(g_main_context_dispatch+0x182)[0xb74c9802]
/usr/lib/libglib-2.0.so.0[0xb74cc7df]
/usr/lib/libglib-2.0.so.0(g_main_context_iteration+0x65)[0xb74ccd45]
/usr/local/Trolltech/Qt-4.2.3/lib/libQtCore.so.4(_ZN20QEventDispatcherGlib13processE ventsE6QFlagsIN10QEventLoop17ProcessEventsFlagEE+0 x58)[0xb764ba68]
/usr/local/Trolltech/Qt-4.2.3/lib/libQtGui.so.4[0xb7a26595]
/usr/local/Trolltech/Qt-4.2.3/lib/libQtCore.so.4(_ZN10QEventLoop13processEventsE6QFl agsINS_17ProcessEventsFlagEE+0x31)[0xb76272e1]
/usr/local/Trolltech/Qt-4.2.3/lib/libQtCore.so.4(_ZN10QEventLoop4execE6QFlagsINS_17P rocessEventsFlagEE+0x7a)[0xb76273ea]
/usr/local/Trolltech/Qt-4.2.3/lib/libQtCore.so.4(_ZN16QCoreApplication4execEv+0xa8)[0xb76297e8]
/usr/local/Trolltech/Qt-4.2.3/lib/libQtGui.so.4(_ZN12QApplication4execEv+0x27)[0xb79a6cf7]
./PL09[0x80527ac]
/lib/tls/i686/cmov/libc.so.6(__libc_start_main+0xdc)[0xb72578cc]
./PL09(_ZN6QFrame10paintEventEP11QPaintEvent+0x31)[0x8051311]
======= Memory map: ========
(...)
Aborted (core dumped)

mtrpoland
19th July 2007, 12:58
and gdb backtrace:


(gdb) backtrace
#0 0xffffe410 in __kernel_vsyscall ()
#1 0xb72ab770 in raise () from /lib/tls/i686/cmov/libc.so.6
#2 0xb72acef3 in abort () from /lib/tls/i686/cmov/libc.so.6
#3 0xb72e0d0b in __fsetlocking () from /lib/tls/i686/cmov/libc.so.6
#4 0xb72e6ceb in malloc_usable_size () from /lib/tls/i686/cmov/libc.so.6
#5 0xb72e8ecd in free () from /lib/tls/i686/cmov/libc.so.6
#6 0xb72ea83f in malloc () from /lib/tls/i686/cmov/libc.so.6
#7 0xb7298c79 in iconv_close () from /lib/tls/i686/cmov/libc.so.6
#8 0xb729870a in iconv_open () from /lib/tls/i686/cmov/libc.so.6
#9 0xb7696094 in QIconvCodec::createIconv_t (to=0xb76c0ced "UTF-16",
from=0x6 <Address 0x6 out of bounds>) at codecs/qiconvcodec.cpp:227
#10 0xb76968d7 in QIconvCodec::convertToUnicode (this=0x80a7260,
chars=0xbf84a823 "/home/mtr/Programowanie/Projekty/PersonalLibrarianProject/PL09", len=62) at codecs/qiconvcodec.cpp:68
#11 0xb75f395a in QString::fromLocal8Bit (
str=0xbf84a823 "/home/mtr/Programowanie/Projekty/PersonalLibrarianProject/PL09", size=62) at ../../include/QtCore/../../src/corelib/codecs/qtextcodec.h:94
#12 0xb766a2e3 in QCoreApplication::arguments ()
at kernel/qcoreapplication.cpp:1621
#13 0xb7a3ae7d in sm_performSaveYourself (smd=0x81089a0)
at kernel/qapplication_x11.cpp:4711
#14 0xb7a3bad6 in sm_saveYourselfCallback (smcConn=0x8107fc0,
clientData=0x81089a0, saveType=1, shutdown=0, interactStyle=0)

jacek
19th July 2007, 13:28
#9 0xb7696094 in QIconvCodec::createIconv_t (to=0xb76c0ced "UTF-16",
from=0x6 <Address 0x6 out of bounds>) at codecs/qiconvcodec.cpp:227
#10 0xb76968d7 in QIconvCodec::convertToUnicode (this=0x80a7260, chars=0xbf84a823 "/home/mtr/Programowanie/Projekty/PersonalLibrarianProject/PL09", len=62) at codecs/qiconvcodec.cpp:68

What is that QIconvCodec? What does convertToUnicode() pass as the from parameter to createIconv_t()? It seems that there's a null pointer somewhere.

marcel
19th July 2007, 13:30
I think the problem is in the setCaseSensitive slot.
Could you post the code for it?

EDIT: no, forget about that :)

jpn
19th July 2007, 13:45
What is that QIconvCodec? What does convertToUnicode() pass as the from parameter to createIconv_t()? It seems that there's a null pointer somewhere.
Internals of Qt:


#if defined(Q_OS_HPUX)
# define NO_BOM
# define UTF16 "ucs2"
#elif defined(Q_OS_AIX)
# define NO_BOM
# define UTF16 "UCS-2"
#else
# define UTF16 "UTF-16"
#endif

...

QString QIconvCodec::convertToUnicode(const char* chars, int len, ConverterState *) const
{
if (utf16Codec == reinterpret_cast<QTextCodec *>(~0))
return QString::fromAscii(chars, len);

iconv_t cd = createIconv_t(UTF16, 0); // <---
...
}

...

iconv_t QIconvCodec::createIconv_t(const char *to, const char *from)
{
Q_ASSERT((to == 0 && from != 0) || (to != 0 && from == 0));

iconv_t cd = (iconv_t) -1;
#if defined(__GLIBC__) || defined(GNU_LIBICONV)
// both GLIBC and libgnuiconv will use the locale's encoding if from or to is an empty string
char *codeset = "";
cd = iconv_open(to ? to : codeset, from ? from : codeset); // <---
#else
char *codeset = 0;
#endif
...
}

jacek
19th July 2007, 13:51
iconv_t cd = createIconv_t(UTF16, 0); // <---

to=0xb76c0ced "UTF-16", from=0x6 <Address 0x6 out of bounds>
Something is fishy around here. Maybe the library was corrupted?

pdolbey
19th July 2007, 16:44
Lets see if I undertstand this code.



iconv_t cd = createIconv_t(UTF16, 0);


In reality your traceback implies you mean


iconv_t cd = createIconv_t("UTF-16", NULL);


yet you get



0xb7696094 in QIconvCodec::createIconv_t (to=0xb76c0ced "UTF-16",
from=0x6 <Address 0x6 out of bounds>) at codecs/qiconvcodec.cpp:227


Why do you get 0x6 then? I suggest you re-try using the NULL macro instead of 0.

Pete

mtrpoland
19th July 2007, 17:37
So yo advise me to change the line:

iconv_t cd = createIconv_t(UTF16, 0);
that is placed in some qt file
to

iconv_t cd = createIconv_t(UTF16, NULL);
??
Just don't get the idea why my actions that are actually a commonplace (initialization of two QRadioButton's and its usage) entail a problem I presented above.
It's quite bizarre.

jacek
19th July 2007, 17:39
Why do you get 0x6 then? I suggest you re-try using the NULL macro instead of 0.
The problematic code appears to be a part of Qt and it seems perfectly valid. Furthermore there's an assertion in QIconvCodec::createIconv_t() that should detect this situation.


BTW. There is no such thing as NULL macro in C++, it's defined only for compatibility with C.

jacek
19th July 2007, 17:41
Just don't get the idea why my actions that are actually a commonplace (initialization of two QRadioButton's and its usage) entail a problem I presented above.
It's quite bizarre.
Yes, it is. Can you reproduce that stack trace?

mtrpoland
19th July 2007, 17:50
What do you mean by "reproducing the stack trace" ?

mtrpoland
19th July 2007, 18:20
Guys, I strove to circumvent the issue by placing one checkbox instead of two radios. It's like an ufo... Now the program works but I get 'core dumped' after having exited the application. So I assume there is a problem with destruction...



(gdb) backtrace
#0 0xffffe410 in __kernel_vsyscall ()
#1 0xb720a770 in raise () from /lib/tls/i686/cmov/libc.so.6
#2 0xb720bef3 in abort () from /lib/tls/i686/cmov/libc.so.6
#3 0xb723fd0b in __fsetlocking () from /lib/tls/i686/cmov/libc.so.6
#4 0xb72478bd in mallopt () from /lib/tls/i686/cmov/libc.so.6
#5 0xb7247a44 in free () from /lib/tls/i686/cmov/libc.so.6
#6 0xb7536e5d in QHashData::freeNode (this=0x8112498, node=0x8124af8)
at tools/qhash.cpp:132
#7 0xb7991abd in QHash<unsigned long, QWidget*>::remove (this=0x8108d30,
akey=@0x812498c)
at ../../include/QtCore/../../src/corelib/tools/qhash.h:450
#8 0xb7982eff in QWidgetPrivate::setWinId (this=0x8124950, id=0)
at kernel/qwidget.cpp:1180
#9 0xb79b8dcc in QWidget::destroy (this=0x81248b8, destroyWindow=true,
destroySubWindows=true) at kernel/qwidget_x11.cpp:782
#10 0xb798866c in ~QWidget (this=0x81248b8) at kernel/qwidget.cpp:1162
#11 0xb7bd7ef1 in ~QAbstractButton (this=0x81248b8)
at widgets/qabstractbutton.cpp:572
#12 0xb7c846e5 in ~QToolButton (this=0x81248b8) at widgets/qtoolbutton.cpp:347
#13 0xb75d4ea1 in QObjectPrivate::deleteChildren (this=0x8123978)
at kernel/qobject.cpp:1823
#14 0xb7988649 in ~QWidget (this=0x8123938) at kernel/qwidget.cpp:1158
#15 0xb7c7e844 in ~QToolBar (this=0x8123938) at widgets/qtoolbar.cpp:472
---Type <return> to continue, or q <return> to quit---
#16 0xb75d4ea1 in QObjectPrivate::deleteChildren (this=0x810b300)
at kernel/qobject.cpp:1823
#17 0xb7988649 in ~QWidget (this=0xbf85ebf0) at kernel/qwidget.cpp:1158
#18 0xb7c30c21 in ~QMainWindow (this=0xbf85ebf0) at widgets/qmainwindow.cpp:292
#19 0x080527ca in main ()


The code was altered in mymvc.h:


QGridLayout* qvb;
QLabel* label;
QCheckBox* checkOne;
bool caseSensitive;
};

#endif

and in mymvc.cpp:


label = new QLabel(tr("Enter a character string below"));
checkOne = new QCheckBox(tr("Case Sensitive"));
checkOne->setChecked(true);
caseSensitive = true;
qvb = new QGridLayout();
connect(checkOne,SIGNAL(toggled(bool)),this,SLOT(s etCaseSensitive(bool)));
connect(qcb,SIGNAL(currentIndexChanged(int)),le,SL OT(clear()));
connect(qcb,SIGNAL(currentIndexChanged(int)),qtv,S LOT(filter()));
connect(le,SIGNAL(textChanged(const QString &)),qtv,SLOT(filter()));
connect(model,SIGNAL(fromTVtoVM(int)),this,SIGNAL( doubleClickInTreeView(int)));

qvb->addWidget(label,0,0,1,2);
qvb->addWidget(le,1,0);
qvb->addWidget(checkOne,1,1);
qvb->addWidget(qcb,2,0,1,2);
qvb->addWidget(qtv,3,0,1,2);
setLayout(qvb);

jacek
19th July 2007, 19:11
What do you mean by "reproducing the stack trace" ?
Try running your application again and see whether the stack trace is the same.

pdolbey
19th July 2007, 19:21
BTW. There is no such thing as NULL macro in C++, it's defined only for compatibility with C.

Apparently (and I've only just googled for this)

The standard says that NULL exists, but is implementation-defined.

Section 18.1, line 4 :

"The macro NULL is an implementation-defined C + + null pointer constant
in this International Standard (4.10)."

It also mentions that it is defined in <cstddef>.

Section 4.10 starts by defining a "null pointer constant" :

"A null pointer constant is an integral constant expression (5.19)
rvalue of integer type that evaluates to zero."

In C++ NULL is typically either 0 or 0L (but not ((void*)0) - I was basically suggesting replacing 0 with NULL as I couldn't see any logical reason why the function call should transform '0' into '0x6' unless it was an compiler "implementation" gotcha. I'd always prefer NULL over 0 but thats because I think its more readable, but there seems to be many opinions on this matter.

I didn't realise how deep this problem was in the Qt4 source code as I don't remember seeing the class QIconvCodec in the public API - just found it in the source tree.

Pete

jacek
19th July 2007, 19:47
It also mentions that it is defined in <cstddef>.
Exactly, as I said, it's only for compatibility with C. In the new C++ standard, there will be a nullptr constant, but for now the first paragraph in section 4.10 says: "A null pointer constant is an integral constant expression (5.19) rvalue of integer type that evaluates to zero."


I couldn't see any logical reason why the function call should transform '0' into '0x6' unless it was an compiler "implementation" gotcha.
It could be, but 0 is used as a null pointer in many places in Qt sources, so it shouldn't be a problem.


I'd always prefer NULL over 0 but thats because I think its more readable, but there seems to be many opinions on this matter.
It also causes some problems with templates.


I don't remember seeing the class QIconvCodec in the public API
Neither did I. You can learn new things about Qt every day. ;)

mtrpoland
19th July 2007, 21:06
Being desperate I decided to check whether the flawless QLabel evokes the problem and now I dare say I was trounced.
Why with two QLabels I receive an error and with one all is ok????

Here you have backtrace at 21:59 LT:


(gdb) backtrace
#0 0xffffe410 in __kernel_vsyscall ()
#1 0xb72c4770 in raise () from /lib/tls/i686/cmov/libc.so.6
#2 0xb72c5ef3 in abort () from /lib/tls/i686/cmov/libc.so.6
#3 0xb72f9d0b in __fsetlocking () from /lib/tls/i686/cmov/libc.so.6
#4 0xb73018bd in mallopt () from /lib/tls/i686/cmov/libc.so.6
#5 0xb7301a44 in free () from /lib/tls/i686/cmov/libc.so.6
#6 0xb75f0e5d in QHashData::freeNode (this=0x8112498, node=0x8124af8)
at tools/qhash.cpp:132
#7 0xb7a4babd in QHash<unsigned long, QWidget*>::remove (this=0x8108d30,
akey=@0x812498c)
at ../../include/QtCore/../../src/corelib/tools/qhash.h:450
#8 0xb7a3ceff in QWidgetPrivate::setWinId (this=0x8124950, id=0)
at kernel/qwidget.cpp:1180
#9 0xb7a72dcc in QWidget::destroy (this=0x81248b8, destroyWindow=true,
destroySubWindows=true) at kernel/qwidget_x11.cpp:782
#10 0xb7a4266c in ~QWidget (this=0x81248b8) at kernel/qwidget.cpp:1162
#11 0xb7c91ef1 in ~QAbstractButton (this=0x81248b8)
at widgets/qabstractbutton.cpp:572
#12 0xb7d3e6e5 in ~QToolButton (this=0x81248b8) at widgets/qtoolbutton.cpp:347
#13 0xb768eea1 in QObjectPrivate::deleteChildren (this=0x8123978)
at kernel/qobject.cpp:1823
#14 0xb7a42649 in ~QWidget (this=0x8123938) at kernel/qwidget.cpp:1158
#15 0xb7d38844 in ~QToolBar (this=0x8123938) at widgets/qtoolbar.cpp:472
---Type <return> to continue, or q <return> to quit---
#16 0xb768eea1 in QObjectPrivate::deleteChildren (this=0x810b300)
at kernel/qobject.cpp:1823
#17 0xb7a42649 in ~QWidget (this=0xbfec0a50) at kernel/qwidget.cpp:1158
#18 0xb7ceac21 in ~QMainWindow (this=0xbfec0a50) at widgets/qmainwindow.cpp:292
#19 0x080527ca in main ()


and at 22:00 LT


(gdb) backtrace
#0 0xffffe410 in __kernel_vsyscall ()
#1 0xb71f3770 in raise () from /lib/tls/i686/cmov/libc.so.6
#2 0xb71f4ef3 in abort () from /lib/tls/i686/cmov/libc.so.6
#3 0xb7228d0b in __fsetlocking () from /lib/tls/i686/cmov/libc.so.6
#4 0xb72308bd in mallopt () from /lib/tls/i686/cmov/libc.so.6
#5 0xb7230a44 in free () from /lib/tls/i686/cmov/libc.so.6
#6 0xb751fe5d in QHashData::freeNode (this=0x8112498, node=0x8124af8)
at tools/qhash.cpp:132
#7 0xb797aabd in QHash<unsigned long, QWidget*>::remove (this=0x8108d30,
akey=@0x812498c)
at ../../include/QtCore/../../src/corelib/tools/qhash.h:450
#8 0xb796beff in QWidgetPrivate::setWinId (this=0x8124950, id=0)
at kernel/qwidget.cpp:1180
#9 0xb79a1dcc in QWidget::destroy (this=0x81248b8, destroyWindow=true,
destroySubWindows=true) at kernel/qwidget_x11.cpp:782
#10 0xb797166c in ~QWidget (this=0x81248b8) at kernel/qwidget.cpp:1162
#11 0xb7bc0ef1 in ~QAbstractButton (this=0x81248b8)
at widgets/qabstractbutton.cpp:572
#12 0xb7c6d6e5 in ~QToolButton (this=0x81248b8) at widgets/qtoolbutton.cpp:347
#13 0xb75bdea1 in QObjectPrivate::deleteChildren (this=0x8123978)
at kernel/qobject.cpp:1823
#14 0xb7971649 in ~QWidget (this=0x8123938) at kernel/qwidget.cpp:1158
#15 0xb7c67844 in ~QToolBar (this=0x8123938) at widgets/qtoolbar.cpp:472
---Type <return> to continue, or q <return> to quit---
#16 0xb75bdea1 in QObjectPrivate::deleteChildren (this=0x810b300)
at kernel/qobject.cpp:1823
#17 0xb7971649 in ~QWidget (this=0xbf9e0d70) at kernel/qwidget.cpp:1158
#18 0xb7c19c21 in ~QMainWindow (this=0xbf9e0d70) at widgets/qmainwindow.cpp:292
#19 0x080527ca in main ()


And finally here you have two complete listings...
mymvc.h


#ifndef MTR_SAFETY_DECLARATION_FOR_MYMVC_H
#define MTR_SAFETY_DECLARATION_FOR_MYMVC_H
#include <QWidget>
namespace MTR {
class Book;
class SBook;
}
class myView;
class myModel;
class QVBoxLayout;
class QLabel;
class QComboBox;
class QLineEdit;

class MyMVC : public QWidget {
Q_OBJECT
public:
MyMVC(QList<MTR::Book>* list = 0, QWidget* parent = 0);
void prodModel(QList<MTR::Book>*);
public slots:
void setCaseSensitive(bool cs) { caseSensitive = cs; }
signals:
void doubleClickInTreeView(int);
private:
QList<MTR::SBook>* slist;
QLineEdit* le;
QComboBox* qcb;
myModel* model;
myView* qtv;
QVBoxLayout* qvb;
QLabel* label;
QLabel* whatTheHell; //IF COMMENTED, DOES NOT CAUSE ERROR
bool caseSensitive;
};

#endif



and mymvc.cpp


#include "mymvc.h"
#include "myView.h"
#include "sbook.h"
#include "myModel.h"
#include "myHeaderView.h"
#include <QList>
#include <QVBoxLayout>
#include <QLabel>
#include <QLineEdit>
#include <QComboBox>
#include <QCheckBox>

MyMVC::MyMVC(QList<MTR::Book>* list, QWidget* parent) {
slist = new QList<MTR::SBook>();
for(int i = 0;i<list->size();++i) {
slist->append(MTR::SBook(i,list->value(i)));
}
setFixedSize(590,400);

le = new QLineEdit();
qcb = new QComboBox();
qcb->addItem(tr("filter by Title"));
qcb->addItem(tr("filter by Author"));
qcb->addItem(tr("filter by Publisher"));
qcb->setCurrentIndex(0);

model = new myModel(*slist,le,qcb);
model->filter();

qtv = new myView(model);
qtv->header()->setSortIndicator(0,Qt::DescendingOrder);

label = new QLabel(tr("Enter a character string below"));
whatTheHell = new QLabel(tr("Damn")); //IF COMMENTED, DOES NOT CAUSE ERROR
caseSensitive = true;
qvb = new QVBoxLayout();
connect(qcb,SIGNAL(currentIndexChanged(int)),le,SL OT(clear()));
connect(qcb,SIGNAL(currentIndexChanged(int)),qtv,S LOT(filter()));
connect(le,SIGNAL(textChanged(const QString &)),qtv,SLOT(filter()));
connect(model,SIGNAL(fromTVtoVM(int)),this,SIGNAL( doubleClickInTreeView(int)));

qvb->addWidget(label);
qvb->addWidget(le);
qvb->addWidget(whatTheHell); //IF COMMENTED, DOES NOT CAUSE ERROR
qvb->addWidget(qcb);
qvb->addWidget(qtv);
setLayout(qvb);
}

void MyMVC::prodModel(QList<MTR::Book>* list) {
slist->clear();
for(int i = 0;i<list->size();++i) {
slist->append(MTR::SBook(i,list->value(i)));
}
model->setInternalList(*slist);
qcb->setCurrentIndex(0);
qtv->filter();

}

jacek
19th July 2007, 21:14
How did you install Qt?

jpn
20th July 2007, 20:38
What does valgrind have to say about it?

mtrpoland
21st July 2007, 17:42
Valgrind?
I do not know whether it is useful as not long time ago I played with FlowLayout example (QT 4.2) and valgrind gave me:

==6237== LEAK SUMMARY:
==6237== definitely lost: 88 bytes in 3 blocks.
==6237== indirectly lost: 120 bytes in 10 blocks.
==6237== possibly lost: 744 bytes in 3 blocks.
==6237== still reachable: 322,563 bytes in 4,588 blocks.
==6237== suppressed: 0 bytes in 0 blocks.


Now my 1600+ lines application gives me:

==6214== LEAK SUMMARY:
==6214== definitely lost: 449 bytes in 32 blocks.
==6214== indirectly lost: 1,526 bytes in 36 blocks.
==6214== possibly lost: 744 bytes in 3 blocks.
==6214== still reachable: 331,034 bytes in 4,629 blocks.
==6214== suppressed: 0 bytes in 0 blocks.

So I suppose that some of those are because of qt libraries... Am I right?

Anyway, I may write some parts of valgrind message after checking my application.

marcel
21st July 2007, 17:54
I don't think this is getting anywhere.
If the app is only around 1600 lines, then why don't you post it here?
Would that be possible? Then someone could test it.

Regards

mtrpoland
21st July 2007, 18:27
Below are links to working application (I have circumvented the problem above) and package of code files and file containing some data to test program (one humble *.dat file).

Anyway, I would be glad if someone experienced checked some of my code for bugs and bad habits. I know it is difficult to ask you for such thing but marcel suggested such a solution himself.

The "funny" thing is when I de-comment code connected to QTranslator in main.cpp I get SIGSEV gift. :(
In other words I cannot translate my application using .ts file made by Linguist.

So my inference is that there is some crucial memory management bug in MY code that sometimes throws irrational SIGSEV, blocking me of using certain normal ways of programming.

I just cannot find it!

Program and code package in:
http://www.mjakobczyk.pl/pub/code/

marcel
21st July 2007, 18:50
I compiled your application( on Windows, Qt 4.3 ) but I cannot get it to crash( I uncommented the translator lines in main).
Could you say what steps are involved?

Regards

jpn
21st July 2007, 18:51
Here's at least one issue that prevents it from launching for me:


void MWin::initialization(void) {
...
tableViewWidget = new MyMVC(list); // list is yet uninitialized
...
list = new QList<MTR::Book>; // it's being initialized somewhere here afterwards
...
}

I would suggest allocating QList objects on the stack and passing them as references. Allocating them on the heap is more error prone. QList is an implicitly shared class (http://doc.trolltech.com/4.3/shared.html) so unmodified copies are cheap.

marcel
21st July 2007, 18:58
Yeah, that and correct the following from:


namespace MTR {
class Book;
class SBook;
}


to:


namespace MTR {
class Book;
struct SBook;
}


I was getting a few warnings and a linker error because of this.

Regards

mtrpoland
21st July 2007, 21:34
Gentlemen, now all indeed does work. A nod of respect. Thank you very much. Now I see that the key was what highlighted jpn. It destabilized my application.