一般的,在日常使用中,通常默认将一个二维坐标表示为:(x,y)。在开发UI时,如果用户参照此格式输入坐标,可通过qstring的相关操作将此字符串转化为double类型:
QString qstr = "(123.123,456.456)";
QString preQstr = qstr.section(',', 0, 0);
QString afterQstrt = qstr.section(",", 1, 1);
double x = preQstr.section("(", 1, 1).trimmed().toDouble();
double y = afterQstrt.section(")", 0, 0).trimmed().toDouble();
cout << x<< endl;
cout << y << endl;