Results 1 to 5 of 5

Thread: Crash-Segmentation fault

  1. #1
    Join Date
    Aug 2010
    Posts
    107
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Angry Crash-Segmentation fault

    I have a stacked widget and I load classes into the stacked widget. On this form is a combo box (cmbName) that gets populated through an iteration of a database. Then there is a function call to set the currentIndex of the combobox to the index of the item with a specified id number (id from the database) I added another Qdialog and used the same code for setting the currentIndex and in this class the program crashes with a sementation fault. I searched this forum and other areas and searched my code. I could not find any of the things that were mentioned for a segmentation fault. Am I not seeing something? It looks like anytime I try to reference anything to do with the combobox I get the error. What could I be missing?
    Qt Code:
    1. void SectionTimer::restoreName(int id)
    2. {
    3. if (id>=0)
    4. {
    5. qDebug()<<"id in section restore rider"<<id;
    6. qDebug()<<"index in sectionTimer restore name"<<ui->cmbName->currentIndex();//this creates Segmentation fault
    7. int index = ui->cmbName->findData(id);// if I comment out above line, this creates segmentation fault.
    8. //qDebug()<<"index (calculated) in section restore name"<<index;
    9. ui->cmbName->setCurrentIndex(index);
    10. }
    11. else
    12. {
    13. ui->cmbName->setCurrentIndex(0);
    14. }
    15. }
    To copy to clipboard, switch view to plain text mode 
    I use the exact same code elsewhere and there is no problem.
    The id number is correct coming into the code. The index is not (there are only about 10 entries in the combobox)segmentation.jpg The entry for the this pointer doesn't look correct?
    Last edited by poporacer; 11th December 2010 at 23:02.

  2. #2
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Crash-Segmentation fault

    A segmentation fault is typically caused when you try to access memory that hasn't been allocated. A classic example is walking off the end of an array.

    It's impossible to say what the problem is in this case; there's not enough code to make a determination. But I'd first look at whether your combo box is initialized properly, since attempting to access it's elements is what causes the problem.

    The best thing to do would be to run the program in a debugger, which will let you quickly determine the cause of the problem.

  3. #3
    Join Date
    Aug 2010
    Posts
    107
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Crash-Segmentation fault

    I used Designer to place the combobox. I checked the ui_h file and the combobox pointer is listed with the proper name cmbName. I have tried clean and rebuild. The combo box does get populated with this code:
    Qt Code:
    1. void SectionTimer::updateNameComboBox()
    2. {
    3.  
    4. QSqlQuery query;
    5. query.exec("SELECT id,LName, FName FROM master");
    6. ui->cmbName->blockSignals(true);
    7. ui->cmbName->clear();
    8.  
    9. while (query.next())
    10. {
    11. ui->cmbName->addItem(query.value (2).toString()+ " "
    12. + query.value (1).toString(),query.value (0).toInt());
    13. ui->cmbName->blockSignals(false);
    14. }
    15. }
    To copy to clipboard, switch view to plain text mode 
    And if I comment out the code listed that causes the segmentation fault, the program runs and the combobox is populated. I did run the debugger and posted the picture of the output. I tried to figure out how to get the back trace...is that what is shown in the lower left window?
    What else do I need to look at?

  4. #4
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Crash-Segmentation fault

    I can't read your screenshot very well. It looks like 'id' is 12 and 'index' is...some really large number. Are those the values you're expecting?

  5. The following user says thank you to SixDegrees for this useful post:

    poporacer (12th December 2010)

  6. #5
    Join Date
    Aug 2010
    Posts
    107
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Crash-Segmentation fault

    No. I mentioned this in my first post as I thought this might be a problem. There are only around 10 entries in the combobox so the number is way off. Also the "this" pointer where the problem resides has a value of "unavailable sychroneous data". This doesn't look right to me either...but I am a newbie and I don't know what it should look like!
    Thanks for your assistance!

Similar Threads

  1. QWT - Segmentation Fault
    By Wojtek.wk in forum Newbie
    Replies: 0
    Last Post: 17th April 2010, 14:29
  2. Segmentation Fault
    By freekill in forum Qt Programming
    Replies: 2
    Last Post: 5th February 2010, 15:31
  3. Segmentation fault
    By Schimanski in forum Qt Programming
    Replies: 20
    Last Post: 31st August 2009, 16:26
  4. Segmentation fault
    By MarkoSan in forum Qt Programming
    Replies: 23
    Last Post: 19th October 2008, 22:40
  5. Segmentation Fault
    By Krish_ng in forum Qt Programming
    Replies: 8
    Last Post: 7th August 2007, 10:49

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.