PDA

View Full Version : segmentation fault insert QString in QCombobox



regix
7th August 2006, 17:23
void MagickFontDlgImpl::fillPointSizes()
{
int my_pointsizes[] = {4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,22,2 4,26,28,32,48,64,80,96,128,256};
for (int j = 0; j < 28; ++j)
{
this->cboPoint->insertItem(QString::number(my_pointsizes[j]),j);
}

this->cboPoint->setCurrentText(QString::number(this->getpsize()));
}


this code sometimes gives segmentation fault. Although I made the combobox with designer and a similar combobox on the form fills up fine, this one does'nt want to be initiated.



comboTtf = new QComboBox( FALSE, groupBox1, "comboTtf" );
comboTtf->setGeometry( QRect( 128, 71, 111, 22 ) );

textLabel2 = new QLabel( groupBox1, "textLabel2" );
textLabel2->setGeometry( QRect( 11, 111, 111, 25 ) );
textLabel2->setMinimumSize( QSize( 100, 25 ) );
textLabel2->setBackgroundOrigin( QLabel::WidgetOrigin );

cboPoint = new QComboBox( FALSE, groupBox1, "cboPoint" );
cboPoint->setGeometry( QRect( 130, 110, 110, 22 ) );
cboPoint->setEditable( TRUE );
layout105->addWidget( groupBox1 );


this comes from the code generated by designer.

I already cleaned the project and recompiled : no luck

I removed the combo and added a combo with the same name, the code compiled and worked, except some connections were broken. When I corrected the connections the code broke again.

How can I get a combobox in existence????

Reginald

munna
7th August 2006, 17:58
instead of




this->cboPoint->insertItem(QString::number(my_pointsizes[j]),j);



try




this->cboPoint->insertItem(QString::number(my_pointsizes[j]));

regix
7th August 2006, 18:27
No cure, same result : segmentation fault

Somehow the combobox doesn't get instantiated in the constructor. When I comment out the insertstatements en the setcurrenttext and I run the app I can fill in a pointsize in the combobox and the slot works wel : it shows in the preview.

Regix

jacek
7th August 2006, 18:39
Please post the backtrace.

regix
7th August 2006, 19:09
Jacek,

what do you mean with backtrace.
Shall I post the code?
I'm using Qt 3 and kdevelop.

Regix

regix
7th August 2006, 19:29
I threw out the images to make the archive smaller;
As a consequence there will be some errormessages

magick++ library is needed for compiling the code.

Regix

jacek
7th August 2006, 19:49
what do you mean with backtrace.
Compile your project in debug mode and run:
$ gdb /path/app
(gdb) run
<program starts and crashes>
(gbd) bt
<backtrace will be printed here>

regix
7th August 2006, 19:53
(gdb) run
Starting program: /home/reginald/projecten/qt/websitecreator/bin/websitecreator
[Thread debugging using libthread_db enabled]
[New Thread 47261255437376 (LWP 18100)]
hg instantiated
reader done parsing
fontmap filled
stringlist inserted
comboTtf filled
fontname is set

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 47261255437376 (LWP 18100)]
0x0000000000415fc4 in QRect::width (this=0x8c)
at /usr/lib/qt3/include/qrect.h:248
248 { return x2 - x1 + 1; }
(gdb) bt
#0 0x0000000000415fc4 in QRect::width (this=0x8c)
at /usr/lib/qt3/include/qrect.h:248
#1 0x000000000041602c in QWidget::width (this=0x0)
at /usr/lib/qt3/include/qwidget.h:768
#2 0x000000000043d976 in MagickFontDlgImpl::drawMagickFont (this=0x719610,
truetypefont=@0x7fffcf6df5a0) at magickfontdlgimpl.cpp:208
#3 0x000000000043f43a in MagickFontDlgImpl::changePointSize (this=0x719610,
newsize=@0x79a510) at magickfontdlgimpl.cpp:260
#4 0x00000000004896ee in MagickFontDlg::qt_invoke (this=0x719610, _id=53,
_o=0x7fffcf6df700) at moc_MagickFontDlg.cpp:161
#5 0x00000000004863ea in MagickFontDlgImpl::qt_invoke (this=0x719610, _id=53,
_o=0x7fffcf6df700) at moc_magickfontdlgimpl.cpp:188
#6 0x00002afbdbcbf7ac in QObject::activate_signal ()
from /usr/lib64/libqt-mt.so.3
#7 0x00002afbdbcc00d6 in QObject::activate_signal ()
from /usr/lib64/libqt-mt.so.3
#8 0x00002afbdbfa8938 in QComboBox::textChanged ()
from /usr/lib64/libqt-mt.so.3
#9 0x00002afbdbfa8a51 in QComboBox::qt_emit () from /usr/lib64/libqt-mt.so.3
#10 0x00002afbdbcbf7ea in QObject::activate_signal ()
from /usr/lib64/libqt-mt.so.3
#11 0x00002afbdbcc00d6 in QObject::activate_signal ()
from /usr/lib64/libqt-mt.so.3
---Type <return> to continue, or q <return> to quit---



Hope this helps

Regix

jacek
7th August 2006, 21:32
#1 0x000000000041602c in QWidget::width (this=0x0)
at /usr/lib/qt3/include/qwidget.h:768
#2 0x000000000043d976 in MagickFontDlgImpl::drawMagickFont (this=0x719610,
truetypefont=@0x7fffcf6df5a0) at magickfontdlgimpl.cpp:208
It seems that you are trying to dereference a null pointer in magickfontdlgimpl.cpp on line 208.

MagickFontDlgImpl::changePointSize() gets invoked because of this line:
this->cboPoint->setCurrentText(QString::number(this->getpsize()));

gfunk
7th August 2006, 21:37
Compile your project in debug mode and run:
$ gdb /path/app
(gdb) run
<program starts and crashes>
(gbd) bt
<backtrace will be printed here>

Fastest gdb tutorial I've ever seen. :p

regix
7th August 2006, 22:26
I changed the code and called setpsize(18) before getpsize is invoked.
The code still segfaults.

The thing is when debugging I noticed that cboPoint was not a known variable in this scope. This made me think that cboPoint was not initialised. I set a breakpoint in the code that was genereted by uic in the place where cboPoint gets instantiated but the execution didn't stop at the breakpoint.

Regix

regix
7th August 2006, 22:33
inline int QRect::width() const
{ return x2 - x1 + 1; }

this is the piece of code called the first time insertItem(..) is called where the code segfaults

Regix

Kumosan
7th August 2006, 22:42
It seems that you are trying to dereference a null pointer in magickfontdlgimpl.cpp on line 208.

MagickFontDlgImpl::changePointSize() gets invoked because of this line:
this->cboPoint->setCurrentText(QString::number(this->getpsize()));

I don't quite understand. Why do you think it is this line? The backtrace goes on. It seems to crash somewhere in QRect. Doesn't this look more like a Qt bug?

Kumosan
7th August 2006, 22:50
inline int QRect::width() const
{ return x2 - x1 + 1; }

this is the piece of code called the first time insertItem(..) is called where the code segfaults

Regix

Ok, it is 23:48 here now and I am dog tired, so I am too lazy now to think about what it means for your layout manager that you are trying to overload a method, which is not virtual. ;-)

Good night

jacek
7th August 2006, 22:51
I don't quite understand. Why do you think it is this line? The backtrace goes on. It seems to crash somewhere in QRect.
Look closely:

#1 0x000000000041602c in QWidget::width (this=0x0)
at /usr/lib/qt3/include/qwidget.h:768
#2 0x000000000043d976 in MagickFontDlgImpl::drawMagickFont (this=0x719610,
truetypefont=@0x7fffcf6df5a0) at magickfontdlgimpl.cpp:208
Some pointer was left uninitialized.


Doesn't this look more like a Qt bug?
No.

jacek
7th August 2006, 22:58
this is the piece of code called the first time insertItem(..) is called where the code segfaults
But the problem is here:

this->fillPointSizes(); //<-- this causes that MagickFontDlgImpl::drawMagickFont()
// is invoked (through signal/slot connection)
...
pixFontView = new MySpecialLabel( this, "pixFontView" ); //<-- here you create pixFontView
// which is used in MagickFontDlgImpl::drawMagickFont()

First create, then use.

Kumosan
8th August 2006, 08:46
Look closely:

Some pointer was left uninitialized.

No.

Outch, thanks. The big red font was necessary yesterday. :o