您尚未登录。

楼主 # 2021-06-25 17:33:48

zhang235hai
会员
注册时间: 2020-04-06
已发帖子: 212
积分: 165

V3S运行Qt程序报错terminate called after throwing an instance of 'std::bad_al

之前用buildroot-2017.08.1编译的根文件系统没有问题
用最新的buildroot-2021.05-rc1编译出来运行Qt程序之后报如下的错误
# ./aaa
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc
Aborted
# ./aaa -platform linuxfb
terminate called after throwing an instance of 'std::bad_alloc'
  what(): 

Qt的配置如下

export QT_ROOT=/usr/lib/qt
export TSLIB_ROOT=/usr/lib/ts
export TSLIB_CONSOLEDEVICE=none
export TSLIB_FBDEVICE=/dev/fb0
export TSLIB_TSDEVICE=/dev/input/event1
export TSLIB_CONFFILE=/etc/ts.conf
export TSLIB_CALIBFILE=/etc/pointercal
export QT_QPA_GENERIC_PLUGINS=tslib:/dev/input/event1
export QT_QPA_PLATFORM_PLUGIN_PATH=$QT_ROOT/plugins
export QT_QPA_PLATFORM=linuxfb:tty=/dev/fb0
export QT_PLUGIN_PATH=$QT_ROOT/plugins
export LD_LIBRARY_PATH=$QT_ROOT/lib:$QT_ROOT/plugins/platforms
export QT_QPA_FB_TSLIB=1

请问大家怎么解决呢?

离线

楼主 #1 2021-06-28 08:20:28

zhang235hai
会员
注册时间: 2020-04-06
已发帖子: 212
积分: 165

Re: V3S运行Qt程序报错terminate called after throwing an instance of 'std::bad_al

自己顶一下,希望得到大家的帮助

离线

#2 2021-06-28 08:37:28

哇酷小二
wechat微信:whycan_cn
所在地: 你猜
注册时间: 2020-04-22
已发帖子: 3,378
积分: 1902
个人网站

Re: V3S运行Qt程序报错terminate called after throwing an instance of 'std::bad_al

代码呢?是不是申请太多内存了?





离线

楼主 #3 2021-06-28 11:07:48

zhang235hai
会员
注册时间: 2020-04-06
已发帖子: 212
积分: 165

Re: V3S运行Qt程序报错terminate called after throwing an instance of 'std::bad_al

哇酷小二 说:

代码呢?是不是申请太多内存了?


我跑了一个最简单的qt侧是程序,就只有两个按钮,没有做任何的功能

离线

#4 2021-06-28 11:15:37

哇酷小二
wechat微信:whycan_cn
所在地: 你猜
注册时间: 2020-04-22
已发帖子: 3,378
积分: 1902
个人网站

Re: V3S运行Qt程序报错terminate called after throwing an instance of 'std::bad_al

https://www.cnblogs.com/BASE64/p/14349333.html

编译出错:
terminate called after throwing an instance of 'std::bad_alloc'what():  std::bad_alloc

分析解决:
【内存不够】:

1,确认系统已占用内存是否正常,排除数据量过大导致的问题,此时系统内存不足导致 std::bad_alloc

【内存剩余】:

1,确认接口调用时,调用和背调接口的的参数是否一致,动态库库调用中若不一致,编译链接通过,但执行可能导致 std::bad_alloc

2,确认是否使用vector,vector超容量时会重新申请二倍内存,因为vector会将老的一块内存,完全拷贝到另一块连续容量为2倍的vector内存中,高峰时内存将时当前系统的3倍,此时可能导致 std::bad_alloc

仔细看了下写的代码,想到一个知识点:vector容器的end指向的并不是容器中最后一个元素,而是最后一个元素的下一个元素地址,所以访问了非法内存,故这里的解决方法是:如果要访问容器中最后一个元素,需要将迭代器--,即it--。

参考一下





离线

页脚

工信部备案:粤ICP备20025096号 Powered by FluxBB

感谢为中文互联网持续输出优质内容的各位老铁们。 QQ: 516333132, 微信(wechat): whycan_cn (哇酷网/挖坑网/填坑网) service@whycan.cn