You are creating the model on stack. It gets destroyed when you leave the function. Create it on heap (using operator new) instead.