I want to create a PointZ with a Z value, then construct a geometry, and then go back to a PointZ but the Z value is lost because .asPoint() is returning a PointXY.
p = QgsPoint(1,2,3)
print(p)
#<QgsPoint: PointZ (1 2 3)>
g = QgsGeometry(p)
print(g)
#<QgsGeometry: PointZ (1 2 3)>
p2 = g.asPoint()
print(p2)
#<QgsPointXY: POINT(1 2)> #The Z is lost
How can I create a PointZ from the geometry?