//creating a point geometry object QgsGeometry geom = QgsGeometry::fromPointXY(QgsPointXY(50.0, -110.0));
//creating a WKT string QString wkt = "POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))"; //converting to a geometry object QgsGeometry geom = QgsGeometry::fromWkt(wkt);
//creating a line geometry object QgsGeometry geom = QgsGeometry::fromPolylineXY(QListThis code creates a line geometry object with vertices at (0,0) and (10,10) and calculates its length using the length() method. Package library: QGIS core library package.() << QgsPointXY(0, 0) << QgsPointXY(10, 10)); //calculating the length double length = geom.length();