Results 1 to 6 of 6

Thread: Segmentation fault error

  1. #1
    Join Date
    May 2011
    Posts
    120
    Thanks
    9
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Segmentation fault error

    Hi all

    I am facing a error segmentation fault in the following code

    Qt Code:
    1. mapper = new QSignalMapper ();
    2.  
    3. for(int i=0; i<obj_schedule_table->rowCount(); i++)
    4. {
    5. QWidget *widget1;
    6. widget1 = obj_schedule_table->cellWidget(i,3);
    7. QComboBox *combo = dynamic_cast<QComboBox*>(widget1->children().at(1));
    8. combo->setEditable(false);
    9.  
    10. mapper->setMapping(combo, i);
    11. connect(combo, SIGNAL(activated(QString)), mapper, SLOT (map()));
    12. }
    13. connect(mapper, SIGNAL(mapped(int)), this, SLOT(set_item_combobox_type(int)));
    To copy to clipboard, switch view to plain text mode 

    I know it may be due to my code is pointing some null pointer but i am not understanding what is the cause of error.

    Thanks in advance.

  2. #2
    Join Date
    Apr 2011
    Location
    Russia
    Posts
    85
    Thanks
    2
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Segmentation fault error

    Qt Code:
    1. mapper = new QSignalMapper();
    2.  
    3. for (int i=0; i < obj_schedule_table->rowCount(); i++)
    4. {
    5. QWidget *widget1 = obj_schedule_table->cellWidget( i, 3 );
    6. QComboBox *combo = dynamic_cast<QComboBox *>( widget1->children().at(1) );
    7.  
    8. if (combo)
    9. {
    10. combo->setEditable( false );
    11. mapper->setMapping( combo, i );
    12. connect(combo, SIGNAL(activated(QString)), mapper, SLOT (map()));
    13. }
    14. }
    15.  
    16. connect(mapper, SIGNAL(mapped(int)), this, SLOT(set_item_combobox_type(int)));
    To copy to clipboard, switch view to plain text mode 

    widget1->children().at(1)? Maybe widget1->children().count() < 1?

  3. #3
    Join Date
    May 2011
    Posts
    120
    Thanks
    9
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Segmentation fault error

    Does anybody help me what is wrong with above code.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Segmentation fault error

    Either widget1 or widget1->children().at(1) is an invalid pointer.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Segmentation fault error

    did you tried to step debug your code?

  6. #6
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Segmentation fault error

    If you don't know how to use the debugger (and if you don't, how do you expect to become a good programmer?), modify your code to tell you what's wrong:

    Qt Code:
    1. #include <QMessageBox>
    2.  
    3. mapper = new QSignalMapper ();
    4.  
    5. if ( obj_schedule_table != 0 )
    6. {
    7. for(int i=0; i<obj_schedule_table->rowCount(); i++)
    8. {
    9. QWidget * widget1 = obj_schedule_table->cellWidget(i,3);
    10. if ( widget1 != 0 )
    11. {
    12. QComboBox * combo = dynamic_cast<QComboBox*>(widget1->children().at(1));
    13. if ( combo != 0 )
    14. {
    15. combo->setEditable(false);
    16.  
    17. mapper->setMapping(combo, i);
    18. connect(combo, SIGNAL(activated(QString)), mapper, SLOT (map()));
    19. }
    20. else
    21. QMessageBox::critical( this, "Error", "Pointer to combo is NULL" );
    22. }
    23. else
    24. QMessageBox::critical( this, "Error", "Pointer to widget1 is NULL" );
    25. }
    26. }
    27. else
    28. QMessageBox::critical( this, "Error", "Pointer to obj_schedule_table is NULL" );
    29.  
    30. connect(mapper, SIGNAL(mapped(int)), this, SLOT(set_item_combobox_type(int)));
    To copy to clipboard, switch view to plain text mode 

    Which message box do you see? That should give you a clue about where to look to solve the problem.

Similar Threads

  1. Segmentation Fault
    By Ryan Riffle in forum Qt Programming
    Replies: 4
    Last Post: 16th January 2011, 20:52
  2. building error: Segmentation fault
    By kaycee1 in forum Installation and Deployment
    Replies: 2
    Last Post: 21st October 2010, 10:08
  3. Segmentation Fault error on all Qt examples/demos
    By slscripters in forum Newbie
    Replies: 4
    Last Post: 26th April 2010, 11:00
  4. segmentation fault
    By uchennaanyanwu in forum Newbie
    Replies: 3
    Last Post: 31st July 2008, 16:52
  5. segmentation fault error
    By sagi in forum Installation and Deployment
    Replies: 2
    Last Post: 25th July 2008, 05:37

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.