Search code examples
c++qtlayoutsignalssignals-slots

qt signals cause segmentation fault on connect


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.


Solution

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