Fix some crashes.

Extend the usage of QSharedPointer.