Add some null ptr checks to prevent Qt warnings