First of all you should modify your code so that all of your widgets ( maybe beside a top level widget in main ) and plot items are allocated by new.
Then show your main and how the code above is called.

Uwe