0

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.

TheDudeAbides
  • 420
  • 1
  • 7
  • 21

1 Answers1

2

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();
jdi
  • 90,542
  • 19
  • 167
  • 203
  • Null pointers should result in `connect` returning `false` according to the source. Uninitialized pointers could do just about anything though. – Mat Aug 18 '12 at 16:17
  • Thanks. Just switched out that word – jdi Aug 18 '12 at 16:34
  • That's the problem, everything's initialized. And other signals work. Just the one I try to emit doesn't (at runtime it just segfaults on the connect) – TheDudeAbides Aug 18 '12 at 17:19
  • Fixed it, apparently I called the connect function before initialisation. My code is a mess! – TheDudeAbides Aug 18 '12 at 17:28
  • 1
    Ya sometimes even when you swear you have taken all the steps, you can overlook some order of operations. Always helps to have another eye look at it! – jdi Aug 18 '12 at 17:33
  • Certainly. Had to take a break to see it. I was just editing the OP when it hit me: ConnectUI(); happened before the initialisation... – TheDudeAbides Aug 18 '12 at 17:59