Results 1 to 5 of 5

Thread: Segmentation fault qComboBox

  1. #1
    Join Date
    Mar 2011
    Posts
    34
    Qt products
    Qt4
    Platforms
    Windows

    Default Segmentation fault qComboBox

    Hi

    When I try to clean my combo box to add new values (may not be the same number of elements) I have a segmentation fault. It always happens on the second time where the comboBox is modified. Here's the code:

    Qt Code:
    1. void MenuPrincipal::updateComboBox(std::vector<std::vector<float> > solutions)
    2. {
    3. QString solution;
    4. QList<QString> finalText;
    5. solution = " ";
    6.  
    7. ui->comboBox->clear(); //segmentation fault
    8.  
    9. //adding objects...
    10. for(int i=0;i<solutions.size();i++)
    11. {
    12. solution = "";
    13. solution.append("(");
    14. solution.append(QString::number(i+1));
    15. solution.append(")");
    16. solution.append(" -> ");
    17. for(int j=0;j<6;j++)
    18. {
    19. solution.append(QString::number((double)solutions[i][j],'f',2));
    20. if(j<solutions[i].size()-1)solution.append(" , ");
    21. }
    22. finalText.push_back(solution);
    23. }
    24.  
    25. QStringList longerList = (finalText);
    26. this->ui->comboBox->addItems(longerList);
    27. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Segmentation fault qComboBox

    Are you sure clear() causes crash ? Can you post backtrace ?
    I see another problem in this code - you have to check if solutions[i] have enough elements before trying to access it, try this way:
    Qt Code:
    1. const int count = solutions[i].count();
    2. for(int j=0;j<6;j++){
    3. if( j < count ){
    4. solution.append(QString::number((double)solutions[i][j],'f',2));
    5. if(j<count-1) solution.append(" , ");
    6. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Mar 2011
    Posts
    34
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Segmentation fault qComboBox

    You can see here how I check where's the error:

    First step
    first update.jpg
    Second step
    second step.jpg

    I control the number of elements of solution in another function.

  4. #4
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Segmentation fault qComboBox

    Have you tried to run with debugger ? It will show you where it crashed exactly (you can clearly see if its inside QComboBox class).

  5. #5
    Join Date
    Sep 2011
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Segmentation fault qComboBox

    Hi,

    I have had the same problem. Every time my application would modify the QComboBox object there was a high probability that a segmentation fault would occur. I have solved the problem by disabling the QComboBox. Example code is the following:

    Qt Code:
    1. comboBoxComponent->setDisabled(true);
    2. comboBoxComponent->clear();
    3. comboBoxComponent->setDisabled(false);
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Segmentation Fault
    By jmc in forum Qt Tools
    Replies: 4
    Last Post: 24th February 2010, 20:08
  2. segmentation fault
    By navid in forum Qt Programming
    Replies: 3
    Last Post: 20th December 2009, 11:40
  3. A QComboBox item produces segmentation fault when used
    By prykHetQuo in forum Qt Programming
    Replies: 3
    Last Post: 18th March 2009, 23:13
  4. Segmentation Fault?!
    By r07f1 in forum Newbie
    Replies: 2
    Last Post: 11th April 2008, 15:10
  5. segmentation fault insert QString in QCombobox
    By regix in forum Qt Programming
    Replies: 16
    Last Post: 8th August 2006, 08:46

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.