Correctly delete QSharedPointers
Only delete a widget if it still exists