std::字符串值在Qt 5中损坏
std::string values become corrupted in Qt 5
我正试图在Qt5项目中使用Presage文本预测平台,但由于std::字符串损坏,一直出现错误。
我有一个为预测系统提供字符串上下文的类:
class SomeClass : public ParentClass
{
public:
SomeClass(const std::string& _past_context) : past_context(_past_context) { }
std::string get_past_stream() const {
return past_context;
}
std::string get_future_stream() const { return empty; }
private:
const std::string& past_context;
const std::string empty;
};
这个上下文在Presage代码中调用如下:
std::string ContextTracker::getToken(const int index) const
{
std::stringstream pastStringStream(context_tracker_callback->get_past_stream());
...
}
如果我在get_past_stream
方法内发送past_context
到std::out
,它会显示正确的字符串。如果我在getToken
方法中发送get_past_stream
的结果,我会得到损坏的数据。
更新〔2016-07-28〕:
为了澄清这个问题并删除重复标签:这个问题只在使用Qt5时发生。使用g++
编译一个仅由SomeClass
和Presage上下文调用程序组成的测试用例效果良好。当在Qt5中使用STL时,字符串在用作返回值后会损坏。
在Qt5中将std::string
作为返回值的可能性缩小后,我在这里发现了类似的问题:"std::string"没有名为front[closed]的成员
似乎Qt5必须明确配置为使用C++11 STL。因此,添加CONFIG += c++11
也解决了我的问题。
相关文章:
- 为什么会发生堆损坏
- Qt VTK交互风格的信号到小部件
- QT在错误的班级中寻找空位
- 具有奇怪重复模板模式的派生类中的成员变量已损坏
- 如何在选项卡视图Qt中设置一个新项目,并保存以前的项目
- 如何在Qt窗口小部件中使用QStringView(或QStringRef)
- 如何在Qt C++中更改光标
- 如何在MS Visual Studio 2019中运行QT UI
- QT通过C++添加映射QML项目
- libssh 的函数在构建 libssh 时无法在 Qt 和 cmake 错误中找到
- 如何将点击的信号和插槽添加到qt中的自定义按钮中
- Qt C++静态thread_local QNetworkAccessManager是线程应用程序的好选择吗
- 使用Qt C++计算类似Git的SHA1哈希
- Qt focusObjectChanged example?
- 平均图像时图像损坏
- Qt插槽参数已损坏
- 示例提供的代码上的Qt堆损坏
- Qt项目中按位或运算符损坏
- Qt Creator错误:LNK1123:转换到COFF时失败:文件无效或损坏
- std::字符串值在Qt 5中损坏