这个问题必须记下来!一个指针错误The inferior stopped because it received a signal from the operating system.
足足查找了一整天,濒临崩溃时,总算挖出来了。
我一个大项目被我层层删减排查,最后删到只剩四行显示图片的代码,只要有scene.addItem(&pixmapItem); 关闭窗口退出时就会在MainWindow析构函数处报上错。注释掉就能正常退出程序。
最后还是跟以前运行正常的程序逐行比较,才挖出问题在头文件对场景scene和图元item对象的创建顺序上。
private:
Ui::MainWindow *ui;
QGraphicsScene scene;
QGraphicsPixmapItem pixmapItem; //这个正确!!!!
QImage image;
QImage image;
QGraphicsPixmapItem pixmapItem; // 这个居然错误!!!!
QGraphicsScene scene;
程序退出时报如下错:

删减后的

博客作者遇到了一个Qt编程中的问题,当QGraphicsScene对象在QGraphicsPixmapItem之后定义时,程序在退出时会触发指针错误。在排查一整天后,作者发现错误在于QGraphicsPixmapItem先于QGraphicsScene创建,导致QGraphicsScene析构时删除了QGraphicsPixmapItem,随后主程序尝试再次删除该对象,从而引发错误。解决方案是确保先创建QGraphicsScene,再创建QGraphicsPixmapItem。
最低0.47元/天 解锁文章

被折叠的 条评论
为什么被折叠?



