Results 1 to 9 of 9

Thread: QComboBox Assert Mistake

  1. #1
    Join Date
    Jul 2007
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default QComboBox Assert Mistake

    I have a filled QComboBox, I want to clear it and fill it again. I do that with the following code:

    // clear the comboBox
    ui.staHealthNameCombo->clear();

    // put the QStringList to the Combobox
    ui.staHealthNameCombo->addItems(newAssuredComboStringList);


    When calling the addItems function I always get :

    ASSERT failure in QList<T>:: at:"index out of range" in c:\...\qt4.2.2\...\qlist.h

    The problem is obviously an out of range error when putting the qStringlist into the combobox. However, I get the same error when I use the addItem - Function that only uses a qstring as an argument.

    Could this be an error in the QT API?

    Thanks for your help.

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QComboBox Assert Mistake

    Could this be an error in the QT API?
    Highly improbable.

    How do you fill that string list?

    Regards

  3. #3
    Join Date
    Jul 2007
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QComboBox Assert Mistake

    This is the code of filling the Stringlist:

    QString insuranceName;
    // append all InsuranceNames from EDCHEALTHINSURANCE
    for (int i=0; i<allhealthinsurances.size(); ++i)
    {
    insuranceName = allhealthinsurances.at(i)->assuredname();

    newAssuredComboStringList << insuranceName;
    }

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QComboBox Assert Mistake

    What does allhealthinsurances.at(i)->assuredname() returns? Is it a copy of a QString or exactly its QString, the one it contains?
    Maybe you destroy allhealthinsurances( along with its contents), and the string list becomes invalid by the time you add it to the combo. But this only if it is a reference to the original one.

    What if you try to add the items in the combo one by one, and not the whole list at once? What happens then?

    Regards

  5. #5
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QComboBox Assert Mistake

    Can you post a minimal version of the code that compiles and also reproduces the problem?

    Regards

  6. #6
    Join Date
    Jul 2007
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QComboBox Assert Mistake

    [HTML]
    // fill ComboBox again
    // get all Healthinsurances
    QList<RefPointer<HealthInsurance>> allhealthinsurances;
    healthinsuranceDao.loadAllByPatientID(allhealthins urances, patient->id());

    QStringList newAssuredComboStringList;

    QString insuranceName;
    // append all InsuranceNames from EDCHEALTHINSURANCE
    for (int i=0; i<allhealthinsurances.size(); ++i)
    {
    insuranceName = allhealthinsurances.at(i)->assuredname();

    newAssuredComboStringList << insuranceName;
    }
    ui.staHealthNameCombo->clear();
    // put the QStringList to the Combobox
    ui.staHealthNameCombo->addItems(newAssuredComboStringList);[/HTML]

    The code is the same as I posted above.

    When I put use the function ui.staHealthNameCombo->addItem(insuranceName) in the for loop I get the same result.
    insuranceName is a QString and Dao Object->assuredname() also returns a QString so that is not the problem.

    If I debug the program I have the right values in the variables.
    I also tried printing out the number of values in the comboBox before and after clearing, but they are correct.


  7. #7
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QComboBox Assert Mistake

    Are you sure the ASSERT isn't raised here?
    Qt Code:
    1. for (int i=0; i<allhealthinsurances.size(); ++i)
    2. {
    3. insuranceName = allhealthinsurances.at(i)->assuredname();
    4.  
    5. newAssuredComboStringList << insuranceName;
    6. }
    To copy to clipboard, switch view to plain text mode 

    Because it makes no sense to get an index out of bounds for a pre-filled string list.
    Unless the memory gets corrupted somehow.
    Anyway, everything so far looks like memory violations to me.

    If you get the same error if you fill the combo in the above for loop, the the error isn't in the string list. More likely in allhealthinsurances. Are you positive this is filled correctly.

    What is RefPointer?

    It is pretty hard to find the problem like this.
    But debugging it carefully should reveal the problem.

    Regards

  8. #8
    Join Date
    Jul 2007
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QComboBox Assert Mistake

    Quote Originally Posted by marcel View Post
    Are you sure the ASSERT isn't raised here?
    Qt Code:
    1. for (int i=0; i<allhealthinsurances.size(); ++i)
    2. {
    3. insuranceName = allhealthinsurances.at(i)->assuredname();
    4.  
    5. newAssuredComboStringList << insuranceName;
    6. }
    To copy to clipboard, switch view to plain text mode 
    Yes I am very sure!

    Because it makes no sense to get an index out of bounds for a pre-filled string list.
    Unless the memory gets corrupted somehow.
    Anyway, everything so far looks like memory violations to me.

    If you get the same error if you fill the combo in the above for loop, the the error isn't in the string list. More likely in allhealthinsurances. Are you positive this is filled correctly.
    I use allhealthinsurances a couple of times before. I works perfectly.


    It is pretty hard to find the problem like this.
    But debugging it carefully should reveal the problem.
    I know. But for me too right now
    Thanks for your hints, I will try debugging it again.

  9. #9
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QComboBox Assert Mistake

    If the problem is indeed in addItems/addItem after a clear() is issued, then could you try with insertItem(-1, insuranceName)?

    This always prepends the item to the item list.,

    Regards

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.