qt信号导致连接上的分段故障 [英] qt signals cause segmentation fault on connect

查看:371
本文介绍了qt信号导致连接上的分段故障的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个充当窗口的小部件,当按下按钮时,它只是发出信号:

I made a widget that behaves as a window and when a button is pressed it simply emits a signal:

signals:
    void SaveTask( void );

在我的mainwindow.cpp文件中定义(在构造函数中):

in my mainwindow.cpp I define (in the constructor):

connect( taskWindow, SIGNAL(SaveTask()), task_view, SLOT(UpdateFromTasks()) );

taskWindow =指向此信号发出的窗口的指针. task_view =指向带有插槽的mainwindow中的treewidget的指针.

taskWindow = pointer to window where this signal emits. task_view = pointer to treewidget in mainwindow with a slot.

其设计目的是使您在保存任务时将其显示在树状视图中.

It is designed so that when you save a task it is displayed in the treeview.

不幸的是,当我尝试运行该程序时,它会在连接线上造成段错误;当我删除它时,该程序就可以正常运行(当然除了此功能).它确实可以编译,并且所有元素都已初始化且可用.我根本看不出这怎么会失败.

unfortunately when I try to run the program it causes a segfault on the connect line, when I remove it the program just runs fine (apart from this functionality ofcourse). It does compile and all elements are initialized and useable. I simply don't see how this can fail.

推荐答案

似乎在初始化taskWindow或task_view并使用未初始化的指针之前,您正在进行连接.

It seems like maybe you are doing the connection before you have initalized the taskWindow or task_view and are using uninitialized pointers.

您也可以尝试使用此签名(应该是相同的东西,但是只是为了很好的衡量)

Also you could try this signature (which should be the same thing, but just for good measure)

signals:
    void SaveTask();

这篇关于qt信号导致连接上的分段故障的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆