PDA

View Full Version : *** glibc detected ***: free(): invalid pointer



codebehind
20th September 2008, 14:34
I've make an empty dialog with QtDesigner.

then I've created a calss:
myClass.h

class myClass : public QWidget, private Ui::myForm
{
Q_OBJECT
public:
myClass(QWidget *parent=0);
~myClass();
};

myClass.cpp

myClass::myClass(QWidget *parent): QWidget(parent)
{
qDebug()<<"Initializing Form";
setupUi((QDialog *)this);
}

myClass::~myClass(){}

main.cpp

int main( int argc, char **argv )
{
QApplication a( argc, argv );
myClass *p = new myClass();
//myClass p;

p->show();
//p.show();

return a.exec();
}


after running the app it crash

Initializing Form
*** glibc detected *** ./jBox.x: free(): invalid pointer: 0x0000000000666ef0 ***
======= Backtrace: =========
/lib64/libc.so.6[0x2b737c4914ba]
/lib64/libc.so.6(cfree+0x8c)[0x2b737c49511c]
/usr/lib64/qt-4.4.1/lib/libQtCore.so.4(_ZN23QCoreApplicationPrivate27remov ePostedEvents_unlockedEP7QObjectiP11QThreadData+0x 108)[0x2b737b1635e8]
/usr/lib64/qt-4.4.1/lib/libQtCore.so.4(_ZN16QCoreApplication18removePosted EventsEP7QObjecti+0x93)[0x2b737b163963]
/usr/lib64/qt-4.4.1/lib/libQtGui.so.4(_ZN7QWidgetD2Ev+0x15c)[0x2b7378e5d45c]
./jBox.x(_ZN8qJukeBoxD0Ev+0x2e)[0x403e20]
/usr/lib64/qt-4.4.1/lib/libQtGui.so.4(_ZN7QDialog18setSizeGripEnabledEb+0x 56)[0x2b7379229ea6]
./jBox.x(_ZN9Ui_jbForm7setupUiEP7QDialog+0x159)[0x4048ab]
./jBox.x(_ZN8qJukeBoxC1EP7QWidget+0xc4)[0x403f82]
./jBox.x(main+0x42)[0x403c06]
/lib64/libc.so.6(__libc_start_main+0xf4)[0x2b737c43e074]
./jBox.x(_ZNK7QWidget6metricEN12QPaintDevice17PaintD eviceMetricE+0xa1)[0x403a19]
======= Memory map: ========
00400000-00406000 r-xp 00000000 08:0e 925727 jBox.x
00605000-00606000 rw-p 00005000 08:0e 925727 jBox.x
00606000-00681000 rw-p 00606000 00:00 0 [heap]
2b7378a48000-2b7378a62000 r-xp 00000000 08:06 138178 /lib64/ld-2.7.so
2b7378a62000-2b7378a64000 rw-p 2b7378a62000 00:00 0
2b7378c61000-2b7378c62000 r--p 00019000 08:06 138178 /lib64/ld-2.7.so
2b7378c62000-2b7378c63000 rw-p 0001a000 08:06 138178 /lib64/ld-2.7.so
2b7378c63000-2b7379547000 r-xp 00000000 08:09 1245629 /usr/lib64/qt-4.4.1/lib/libQtGui.so.4.4.1
2b7379547000-2b7379747000 ---p 008e4000 08:09 1245629 /usr/lib64/qt-4.4.1/lib/libQtGui.so.4.4.1
2b7379747000-2b737978c000 rw-p 008e4000 08:09 1245629 /usr/lib64/qt-4.4.1/lib/libQtGui.so.4.4.1
2b737978c000-2b737978e000 rw-p 2b737978c000 00:00 0
2b737978e000-2b737978f000 r--p 00000000 08:09 1647920 /usr/share/locale/sl_SI.UTF-8/LC_IDENTIFICATION
2b737978f000-2b7379796000 r--s 00000000 08:09 1147127 /usr/lib64/gconv/gconv-modules.cache
2b7379796000-2b7379797000 r--p 00000000 08:09 1425414 /usr/share/locale/sl_SI.UTF-8/LC_MEASUREMENT
2b7379797000-2b7379798000 r--p 00000000 08:09 1647923 /usr/share/locale/sl_SI.UTF-8/LC_TELEPHONE
2b7379798000-2b7379799000 r--p 00000000 08:09 1647915 /usr/share/locale/sl_SI.UTF-8/LC_ADDRESS
2b7379799000-2b737979a000 r--p 00000000 08:09 1425412 /usr/share/locale/sl_SI.UTF-8/LC_NAME
2b737979a000-2b737979b000 r--p 00000000 08:09 1647927 /usr/share/locale/sl_SI.UTF-8/LC_PAPER
2b737979b000-2b737979c000 r--p 00000000 08:09 1648302 /usr/share/locale/en_US.UTF-8/LC_MESSAGES/SYS_LC_MESSAGES
2b737979c000-2b737979d000 r--p 00000000 08:09 1425413 /usr/share/locale/sl_SI.UTF-8/LC_MONETARY
2b73797ad000-2b73797d3000 r-xp 00000000 08:09 1148977 /usr/lib64/libpng12.so.0.25.0
2b73797d3000-2b73799d3000 ---p 00026000 08:09 1148977 /usr/lib64/libpng12.so.0.25.0
2b73799d3000-2b73799d4000 rw-p 00026000 08:09 1148977 /usr/lib64/libpng12.so.0.25.0
2b73799d4000-2b73799dc000 r-xp 00000000 08:09 1148972 /usr/lib64/libSM.so.6.0.0
2b73799dc000-2b7379bdb000 ---p 00008000 08:09 1148972 /usr/lib64/libSM.so.6.0.0
2b7379bdb000-2b7379bdc000 rw-p 00007000 08:09 1148972 /usr/lib64/libSM.so.6.0.0
2b7379bdc000-2b7379bdd000 rw-p 2b7379bdc000 00:00 0
2b7379bdd000-2b7379bf3000 r-xp 00000000 08:09 1148916 /usr/lib64/libICE.so.6.3.0
2b7379bf3000-2b7379df3000 ---p 00016000 08:09 1148916 /usr/lib64/libICE.so.6.3.0
2b7379df3000-2b7379df4000 rw-p 00016000 08:09 1148916 /usr/lib64/libICE.sAborted


and i'm clueless.

caduel
20th September 2008, 15:02
Lesson of the day: Do not lie to your compiler!

Your class is not a QDialog, so do not cast it to pretend it is.
Inherit your class from QDialog instead of QWidget, drop that cast, and it should work.

(If you create a QMainWindow in designer, inherit from QMainWindow.)

HTH

codebehind
20th September 2008, 17:15
i don't understand...
based on this lesson QtDesigner (http://doc.trolltech.com/4.4/designer-using-a-component.html#the-multiple-inheritance-approach)

i can not see the difference.

lvi
20th September 2008, 17:32
myClass::myClass(QWidget *parent): QWidget(parent)
{
qDebug()<<"Initializing Form";
setupUi((QDialog *)this);
}

myClass::~myClass(){}


caduel is referring to line 4 of this piece of code. You're casting the pointer "this" to a pointer of type QDialog, which is not allowed. The example you're referring to uses setupUi(this), so I don't understand why you're casting the pointer?

If you made a dialog in QtDesigner (and not a widget), your class should inheret from QDialog, as cadual already mentioned:



class myClass : public QDialog, private Ui::myForm

codebehind
20th September 2008, 23:45
my bad...

i haven't look at calculatorform.ui code. it is defined as QWidget and not QDialog.

Thanks for your time and explanations - both of you.

I've done another test app the same way (haven't declared it as QWidget and typecast it in the constructor) and it works just fine... so I repeat the mistake. the difference is that this time the app crashed.