EXPRESSION: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse) - Error after program close?



  • I get the "EXPRESSION: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse)" error after program close., as a pop-up.

    It is caused somewhere in this function below, because it started when I created it, and arises when I call it.
    I call it using:

    @ treeWidget(&fullPack, &sh3dcFullPack);

    @
    I initialize the QTreeWidgetItems in my header file like this:
    @

    QTreeWidgetItem sh3dcFullPack;
    QTreeWidgetItem fullPack;
    

    @

    Function:


  • Moderators

    You create sh3dcFullPack and fullPack on the stack. Then you add them to the tree widget. When tree widget is destroyed it destroys all of its items so basically calls delete on these items. This is of course invalid in case of these two.

    Create them on the heap instead (via new) and let tree widget handle it.
    Apart from that you shouldn't create instances in a header anyway. You won't be able to include it in two places because this would be multiple definition error. Declare just pointers in the header and initialize in cpp. Better yet - put these in a proper class.



  • [quote author="Chris Kawa" date="1389520592"]You create sh3dcFullPack and fullPack on the stack. Then you add them to the tree widget. When tree widget is destroyed it destroys all of its items so basically calls delete on these items. This is of course invalid in case of these two.

    Create them on the heap instead (via new) and let tree widget handle it.
    Apart from that you shouldn't create instances in a header anyway. You won't be able to include it in two places because this would be multiple definition error. Declare just pointers in the header and initialize in cpp. Better yet - put these in a proper class.[/quote]

    That fixed it, thank you. I put pointer declarations in the header and initialized them in the class constructor using "new".


  • Moderators

    Great. I'm glad I could help.
    Please add [solved] to the title to let others know there's an answer here.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.