首页 > 解决方案 > 在 Qt Creator 中调试与运行。不同的数值

问题描述

我在 QtCreator 中从事 C++ Qt 项目。对数据进行了一些操作(例如 std::double 类型)。当我在没有任何断点的情况下开始调试时,我的应用程序会显示正确的数据 (-8.7357)。但是当我运行已经编译的程序时,我得到了(-8)。这种情况可能是什么原因?

下面是我的一段 json 文件:

{
...
"sources": [
    [-8.30000, -1.43300, 0],
    [-8.73575, -1.76287, -0.24404],
    [-8.68767, -1.72513, 0.35267],
    [-8.24991, -1.39526, 0.59671],
    [-7.86225, -1.10313, 0.24404],
    [-7.91233, -1.14087, -0.35267],
    [-8.35009, -1.47074, -0.59671]
]
...
}

解析该文件:

Json::Value root;
std::ifstream jsonFile(pathToJsonFile);
jsonFile >> root;
...
Json::Value srsc = root["sources"];
for (Json::Value::ArrayIndex i = 0; i != srsc.size(); i++)
{
   Json::Value src = Json::arrayValue;
   src = srsc[i];

   Antenna::centerPoint cp;
   cp.x = src.get(Json::ArrayIndex(0), Json::Value()).asDouble();
   cp.y = src.get(Json::ArrayIndex(1), Json::Value()).asDouble();
   cp.z = src.get(Json::ArrayIndex(2), Json::Value()).asDouble();
   an.sources[i] = cp;
}

将数据设置为模型,然后将其显示在屏幕上:

for(unsigned int row = 0; row < an.sources.size(); row++)
{
    model->setData(model->index(row, 0), an.sources[row].x);
    model->setData(model->index(row, 1), an.sources[row].y);
    model->setData(model->index(row, 2), an.sources[row].z);
}
...
ui->sourcesTableView->setModel(model);

我在用着:

我在 Linux astra 4.15.3-2-generic OS
GCC 编译器 - gcc (Debian 6.3.0-18+deb9u1) 6.3.0 20170516.
cmake 版本 3.7.2
gdb 调试器 - GNU gdb (Debian 7.12-6) 7.12。 0.20161007-git

标签: c++qtgcccmakegdb

解决方案


这是我从评论中复制答案。
我的 json 文件使用 ' 。' 小数分隔符。Qt 使用来自 QSystemLocale 的信息,即来自操作系统的区域信息。可能 GDB 调试器使用他自己的设置。这就是为什么我在调试时得到了正确的数据。我更改了文件/usr/share/i18n/locales/ru_RU中的行

decimal_point "<U002C>"

decimal_point "<U002E>"

然后我重新配置了语言环境:

dpkg-reconfigure locales

最后重新启动 Qt Creator,它工作正常。


推荐阅读