qt signals cause segmentation fault on connect

好久不见. 提交于 2019-12-12 00:31:14

问题


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

signals:
    void SaveTask( void );

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

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

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.


回答1:


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();


来源:https://stackoverflow.com/questions/12019929/qt-signals-cause-segmentation-fault-on-connect

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!