Results 1 to 7 of 7

Thread: Clearing a QComboBox causes a crash

  1. #1
    Join Date
    Feb 2007
    Posts
    4
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Clearing a QComboBox causes a crash

    I have a problem clearing the contents of a QComboBox.

    The program I have written has two QComboBox objects in a QMainWindow derived window. Both are populated with QStringlists and, initially, work a treat. However, when I need to re-populate one of them, the program crashes when I call the combo box's clear() method. This happens if I call the method directly or through a signal. It only happens with one of the boxes, not the other. Also, if I have only one box in the window ( the other being commented out) there is no problem.

    Stepping through the code I have found that line number 2910 in QObject.cpp is throwing an exception : -

    try {
    c->receiver->qt_metacall(QMetaObject::InvokeMetaMethod, method, argv ? argv : empty_argv);
    } catch (...) {
    if (c->receiver) {
    c->receiver->d_func()->currentSender = previousSender;
    c->receiver->d_func()->currentSenderSignalIdStart = previousFrom;
    c->receiver->d_func()->currentSenderSignalIdEnd = previousTo;
    }
    throw;

    Here "previousSender" is 0, both "previousFrom" and "previousTo" are -1.

    Any ideas or suggestions will be greatfully received. If you need any further information please feel free to contact me.

    I am using Qt version 4.2.1. The development environment is MS Visual Studio 2003 .NET with Visual C++ .NET with the Qt Visual Studio Integration version 1.1.3.

    AdvThanksance.

    Tony

  2. #2
    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: Clearing a QComboBox causes a crash

    Could you provide a minimal compilable example reproducing the problem?

  3. #3
    Join Date
    Feb 2007
    Posts
    4
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Clearing a QComboBox causes a crash

    I have pared down the code to a minimum so it just includes opening an xml data file, reading in the data and populating the two combo boxes. When the "Go" button is pushed the combo boxes are re-populated with the same data. The crash occurs in the populateView() method of the MissingWords class at the line where the "subject" combo box is cleared.

    See attached zip file for source code and "pro" file.

    Cheers,

    T@H
    Attached Files Attached Files

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Clearing a QComboBox causes a crash

    Well, that's far from minimal, but... :)

    For me it crashed in MissingWords::populateSceneComboBox(), which got called from MissingWords::on_subject_comboBox_currentIndexChan ged() with a null item.
    J-P Nurmi

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

    tony@hitachi (8th March 2007)

  6. #5
    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: Clearing a QComboBox causes a crash

    It is "MissingWords::populateSceneComboBox" that crashes and not clear().
    "subjectitem" argument there is null. Take a look:
    Qt Code:
    1. DomItem* subjectItem = static_cast< DomItem*>( m_CurrentSubjectIndex.internalPointer());
    2. populateSceneComboBox( subjectItem);
    To copy to clipboard, switch view to plain text mode 
    And debugging gives:
    #2 0x0804cba8 in DomItem::child (this=0x0, i=0) at domitem.cpp:75
    #3 0x0804f00c in MissingWords::populateSceneComboBox (this=0xbfb556bc, subjectItem=0x0) at missingwords.cpp:112
    #4 0x0804f0fc in MissingWords::on_subject_comboBox_currentIndexChan ged ( this=0xbfb556bc, index=-1) at missingwords.cpp:152
    Take a look at #3 - "subjectItem=0x0" - a null pointer. This propagates to #2 - "this" is a null pointer as well, therefore you're trying to dereference a null pointer which causes the segmentation fault (or memory access violation in your case).

  7. The following user says thank you to wysota for this useful post:

    tony@hitachi (8th March 2007)

  8. #6
    Join Date
    Feb 2007
    Posts
    4
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Clearing a QComboBox causes a crash

    It looks like the xml file is not being opened successfully, hence the subjectItem pointer is a NULL. When I run the program the xml file is opened and subjectItem is not a NULL pointer.

    Thanks for the input so far.

    Cheers,

    T@H

    P.S. Fair do's, I should have checked in populateSceneComboBox() for a NULL pointer!

  9. #7
    Join Date
    Feb 2007
    Posts
    4
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Clearing a QComboBox causes a crash

    I have the solution.

    When the subject combo box is cleared it generates an "on_subject_comboBox_currentIndexChanged()" signal with an index value of -1. The code does not check the index which means subjectItem is a NULL value which, as you have already pointed out, is what is causing the crash.

    Many thanks for your help.

    T@H

Similar Threads

  1. using QComboBox as an ItemView
    By EricTheFruitbat in forum Qt Programming
    Replies: 3
    Last Post: 24th January 2007, 17:14
  2. QDataWidgetMapper <=> QComboBox best practice
    By saknopper in forum Qt Programming
    Replies: 1
    Last Post: 18th January 2007, 11:50
  3. Crash: using a dialog in a model
    By Brandybuck in forum Qt Programming
    Replies: 3
    Last Post: 11th April 2006, 02:39
  4. QcomboBox items
    By therealjag in forum Newbie
    Replies: 5
    Last Post: 27th March 2006, 09:21
  5. QComboBox +SUSE10.0 +qt4.1 strange behavior
    By antonio.r.tome in forum Qt Programming
    Replies: 6
    Last Post: 20th March 2006, 18: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.