<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def getItem(self, index, altItem=None):
 """ Returns the TreeItem for the given index. Returns the altItem if the index is invalid. """

        if index.isValid():
            item = index.internalPointer()
            if item:
                return item

        #return altItem if altItem is not None else self.invisibleRootItem # TODO: remove
        return altItem