Could you use ```dynamic_cast<TreeItem*>(index.internalPointer())``` instead? That uses RTTI to determine if the interpretation is valid. If it is not a TreeItem object then the value will be NULL.