Results 1 to 17 of 17

Thread: segmentation fault insert QString in QCombobox

  1. #1
    Join Date
    Jan 2006
    Posts
    45
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Unhappy segmentation fault insert QString in QCombobox

    Qt Code:
    1. void MagickFontDlgImpl::fillPointSizes()
    2. {
    3. int my_pointsizes[] = {4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,22,24,26,28,32,48,64,80,96,128,256};
    4. for (int j = 0; j < 28; ++j)
    5. {
    6. this->cboPoint->insertItem(QString::number(my_pointsizes[j]),j);
    7. }
    8.  
    9. this->cboPoint->setCurrentText(QString::number(this->getpsize()));
    10. }
    To copy to clipboard, switch view to plain text mode 

    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.

    Qt Code:
    1. comboTtf = new QComboBox( FALSE, groupBox1, "comboTtf" );
    2. comboTtf->setGeometry( QRect( 128, 71, 111, 22 ) );
    3.  
    4. textLabel2 = new QLabel( groupBox1, "textLabel2" );
    5. textLabel2->setGeometry( QRect( 11, 111, 111, 25 ) );
    6. textLabel2->setMinimumSize( QSize( 100, 25 ) );
    7. textLabel2->setBackgroundOrigin( QLabel::WidgetOrigin );
    8.  
    9. cboPoint = new QComboBox( FALSE, groupBox1, "cboPoint" );
    10. cboPoint->setGeometry( QRect( 130, 110, 110, 22 ) );
    11. cboPoint->setEditable( TRUE );
    12. layout105->addWidget( groupBox1 );
    To copy to clipboard, switch view to plain text mode 

    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

  2. #2
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: segmentation fault insert QString in QCombobox

    instead of

    Qt Code:
    1. this->cboPoint->insertItem(QString::number(my_pointsizes[j]),j);
    To copy to clipboard, switch view to plain text mode 

    try

    Qt Code:
    1. this->cboPoint->insertItem(QString::number(my_pointsizes[j]));
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Posts
    45
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: segmentation fault insert QString in QCombobox

    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

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

    Default Re: segmentation fault insert QString in QCombobox

    Please post the backtrace.

  5. #5
    Join Date
    Jan 2006
    Posts
    45
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: segmentation fault insert QString in QCombobox

    Jacek,

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

    Regix

  6. #6
    Join Date
    Jan 2006
    Posts
    45
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: segmentation fault insert QString in QCombobox

    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
    Attached Files Attached Files

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

    Default Re: segmentation fault insert QString in QCombobox

    Quote Originally Posted by regix
    what do you mean with backtrace.
    Compile your project in debug mode and run:
    Qt Code:
    1. $ gdb /path/app
    2. (gdb) run
    3. <program starts and crashes>
    4. (gbd) bt
    5. <backtrace will be printed here>
    To copy to clipboard, switch view to plain text mode 

  8. #8
    Join Date
    Jan 2006
    Posts
    45
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: segmentation fault insert QString in QCombobox

    Qt Code:
    1. (gdb) run
    2. Starting program: /home/reginald/projecten/qt/websitecreator/bin/websitecreator
    3. [Thread debugging using libthread_db enabled]
    4. [New Thread 47261255437376 (LWP 18100)]
    5. hg instantiated
    6. reader done parsing
    7. fontmap filled
    8. stringlist inserted
    9. comboTtf filled
    10. fontname is set
    11.  
    12. Program received signal SIGSEGV, Segmentation fault.
    13. [Switching to Thread 47261255437376 (LWP 18100)]
    14. 0x0000000000415fc4 in QRect::width (this=0x8c)
    15. at /usr/lib/qt3/include/qrect.h:248
    16. 248 { return x2 - x1 + 1; }
    17. (gdb) bt
    18. #0 0x0000000000415fc4 in QRect::width (this=0x8c)
    19. at /usr/lib/qt3/include/qrect.h:248
    20. #1 0x000000000041602c in QWidget::width (this=0x0)
    21. at /usr/lib/qt3/include/qwidget.h:768
    22. #2 0x000000000043d976 in MagickFontDlgImpl::drawMagickFont (this=0x719610,
    23. truetypefont=@0x7fffcf6df5a0) at magickfontdlgimpl.cpp:208
    24. #3 0x000000000043f43a in MagickFontDlgImpl::changePointSize (this=0x719610,
    25. newsize=@0x79a510) at magickfontdlgimpl.cpp:260
    26. #4 0x00000000004896ee in MagickFontDlg::qt_invoke (this=0x719610, _id=53,
    27. _o=0x7fffcf6df700) at moc_MagickFontDlg.cpp:161
    28. #5 0x00000000004863ea in MagickFontDlgImpl::qt_invoke (this=0x719610, _id=53,
    29. _o=0x7fffcf6df700) at moc_magickfontdlgimpl.cpp:188
    30. #6 0x00002afbdbcbf7ac in QObject::activate_signal ()
    31. from /usr/lib64/libqt-mt.so.3
    32. #7 0x00002afbdbcc00d6 in QObject::activate_signal ()
    33. from /usr/lib64/libqt-mt.so.3
    34. #8 0x00002afbdbfa8938 in QComboBox::textChanged ()
    35. from /usr/lib64/libqt-mt.so.3
    36. #9 0x00002afbdbfa8a51 in QComboBox::qt_emit () from /usr/lib64/libqt-mt.so.3
    37. #10 0x00002afbdbcbf7ea in QObject::activate_signal ()
    38. from /usr/lib64/libqt-mt.so.3
    39. #11 0x00002afbdbcc00d6 in QObject::activate_signal ()
    40. from /usr/lib64/libqt-mt.so.3
    41. ---Type <return> to continue, or q <return> to quit---
    To copy to clipboard, switch view to plain text mode 

    Hope this helps

    Regix

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

    Default Re: segmentation fault insert QString in QCombobox

    Quote Originally Posted by regix
    #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:
    Qt Code:
    1. this->cboPoint->setCurrentText(QString::number(this->getpsize()));
    To copy to clipboard, switch view to plain text mode 

  10. #10
    Join Date
    Apr 2006
    Location
    San Francisco, CA
    Posts
    186
    Thanks
    55
    Thanked 12 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: segmentation fault insert QString in QCombobox

    Quote Originally Posted by jacek
    Compile your project in debug mode and run:
    Qt Code:
    1. $ gdb /path/app
    2. (gdb) run
    3. <program starts and crashes>
    4. (gbd) bt
    5. <backtrace will be printed here>
    To copy to clipboard, switch view to plain text mode 
    Fastest gdb tutorial I've ever seen.
    Software Engineer



  11. #11
    Join Date
    Jan 2006
    Posts
    45
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: segmentation fault insert QString in QCombobox

    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

  12. #12
    Join Date
    Jan 2006
    Posts
    45
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: segmentation fault insert QString in QCombobox

    Qt Code:
    1. inline int QRect::width() const
    2. { return x2 - x1 + 1; }
    To copy to clipboard, switch view to plain text mode 

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

    Regix

  13. #13
    Join Date
    Aug 2006
    Posts
    221
    Thanks
    3
    Thanked 29 Times in 19 Posts

    Default Re: segmentation fault insert QString in QCombobox

    Quote Originally Posted by jacek
    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:
    Qt Code:
    1. this->cboPoint->setCurrentText(QString::number(this->getpsize()));
    To copy to clipboard, switch view to plain text mode 
    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?

  14. #14
    Join Date
    Aug 2006
    Posts
    221
    Thanks
    3
    Thanked 29 Times in 19 Posts

    Default Re: segmentation fault insert QString in QCombobox

    Quote Originally Posted by regix
    Qt Code:
    1. inline int QRect::width() const
    2. { return x2 - x1 + 1; }
    To copy to clipboard, switch view to plain text mode 

    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

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

    Default Re: segmentation fault insert QString in QCombobox

    Quote Originally Posted by Kumosan
    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.

    Quote Originally Posted by Kumosan
    Doesn't this look more like a Qt bug?
    No.

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

    Default Re: segmentation fault insert QString in QCombobox

    Quote Originally Posted by regix
    this is the piece of code called the first time insertItem(..) is called where the code segfaults
    But the problem is here:
    Qt Code:
    1. this->fillPointSizes(); //<-- this causes that MagickFontDlgImpl::drawMagickFont()
    2. // is invoked (through signal/slot connection)
    3. ...
    4. pixFontView = new MySpecialLabel( this, "pixFontView" ); //<-- here you create pixFontView
    5. // which is used in MagickFontDlgImpl::drawMagickFont()
    To copy to clipboard, switch view to plain text mode 
    First create, then use.

  17. The following user says thank you to jacek for this useful post:

    regix (8th August 2006)

  18. #17
    Join Date
    Aug 2006
    Posts
    221
    Thanks
    3
    Thanked 29 Times in 19 Posts

    Default Re: segmentation fault insert QString in QCombobox

    Quote Originally Posted by jacek
    Look closely:

    Some pointer was left uninitialized.

    No.
    Outch, thanks. The big red font was necessary yesterday.

Similar Threads

  1. why does qt program meet segmentation fault?
    By wquanw in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 15th May 2006, 16:52
  2. (Another) segmentation fault
    By Lebowski in forum Qt Programming
    Replies: 27
    Last Post: 6th April 2006, 06:33
  3. Replies: 2
    Last Post: 25th March 2006, 06:54
  4. Icons missing => segmentation fault
    By antonio.r.tome in forum Qt Programming
    Replies: 4
    Last Post: 8th March 2006, 16:30
  5. [qmake_image_collection.cpp] Segmentation fault
    By CrazyLegz in forum KDE Forum
    Replies: 1
    Last Post: 4th February 2006, 11:43

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.