title: Why is my Qt slot causing my program to crash?
body: <p>So I've written the following Qt slot definition:</p>
  
  <p>(header)</p>
  
  <pre><code>public slots:
      void test1();
  </code></pre>
  
  <p>(method)</p>
  
  <pre><code>void myClass:test1()
  {
     //...
  }
  </code></pre>
  
  <p>If I put some code in my slot definition, such as code to display a new window or a new messagebox, the code executes fine. However, if I stick in my own function, such as the following:</p>
  
  <pre><code>QString myClass::run_func(QString phase)
  {
      myOtherClass* moc = new myOtherClass();
      moc-&gt;run(phase);
  }
  
  void myClass:test1()
  {
     run_func("hello world");
  }
  </code></pre>
  
  <p>My program crashes, with the following message:</p>
  
  <pre><code>Sleep/Wake UUID: 03C9AE1C-32F3-4F2E-8396-80655C0AE1EA
  
  Crashed Thread:  0  Dispatch queue: com.apple.main-thread
  
  Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
  Exception Codes: KERN_INVALID_ADDRESS at 0x0000010a08062020
  
  VM Regions Near 0x10a08062020:
      CG shared images       00000001c7eb2000-00000001c7eba000 [   32K] r--/r-- SM=SHM  
  --&gt; 
      STACK GUARD            00007fff5bc00000-00007fff5f400000 [ 56.0M] ---/rwx SM=NUL  stack guard for thread 0
  
  Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
  0   QtCore                          0x0000000100d0c344 QCoreApplicationPrivate::sendThroughObjectEventFilters(QObject*, QEvent*) + 52
  1   QtWidgets                       0x0000000100040f19 QApplicationPrivate::notify_helper(QObject*, QEvent*) + 281
  2   QtWidgets                       0x00000001000427b2 QApplication::notify(QObject*, QEvent*) + 1442
  3   QtCore                          0x0000000100d0c0b2 QCoreApplication::notifyInternal(QObject*, QEvent*) + 114
  4   QtWidgets                       0x0000000100096344 QWidgetWindow::event(QEvent*) + 212
  5   QtWidgets                       0x0000000100040f2c QApplicationPrivate::notify_helper(QObject*, QEvent*) + 300
  6   QtWidgets                       0x0000000100043a1d QApplication::notify(QObject*, QEvent*) + 6157
  7   QtCore                          0x0000000100d0c0b2 QCoreApplication::notifyInternal(QObject*, QEvent*) + 114
  8   QtGui                           0x000000010068c9be QGuiApplicationPrivate::processKeyEvent(QWindowSystemInterfacePrivate::KeyEvent*) + 190
  9   QtGui                           0x000000010068b5c8 QGuiApplicationPrivate::processWindowSystemEvent(QWindowSystemInterfacePrivate::WindowSystemEvent*) + 840
  10  QtGui                           0x000000010067b338 QWindowSystemInterface::sendWindowSystemEvents(QFlags&lt;QEventLoop::ProcessEventsFlag&gt;) + 136
  11  libqcocoa.dylib                 0x000000010441a4c7 QCocoaEventDispatcherPrivate::processPostedEvents() + 295
  12  libqcocoa.dylib                 0x000000010441afd8 QCocoaEventDispatcherPrivate::postedEventsSourceCallback(void*) + 40
  13  com.apple.CoreFoundation        0x00007fff89c72731 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
  14  com.apple.CoreFoundation        0x00007fff89c63ea2 __CFRunLoopDoSources0 + 242
  15  com.apple.CoreFoundation        0x00007fff89c6362f __CFRunLoopRun + 831
  16  com.apple.CoreFoundation        0x00007fff89c630b5 CFRunLoopRunSpecific + 309
  17  com.apple.HIToolbox             0x00007fff874eea0d RunCurrentEventLoopInMode + 226
  18  com.apple.HIToolbox             0x00007fff874ee685 ReceiveNextEventCommon + 173
  19  com.apple.HIToolbox             0x00007fff874ee5bc _BlockUntilNextEventMatchingListInModeWithFilter + 65
  20  com.apple.AppKit                0x00007fff8e83a3de _DPSNextEvent + 1434
  21  com.apple.AppKit                0x00007fff8e839a2b -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 122
  22  com.apple.AppKit                0x00007fff8e82db2c -[NSApplication run] + 553
  23  libqcocoa.dylib                 0x0000000104419d44 QCocoaEventDispatcher::processEvents(QFlags&lt;QEventLoop::ProcessEventsFlag&gt;) + 2404
  24  QtCore                          0x0000000100d0964d QEventLoop::exec(QFlags&lt;QEventLoop::ProcessEventsFlag&gt;) + 397
  25  QtCore                          0x0000000100d0c652 QCoreApplication::exec() + 354
  26  com.yourcompany.PwrCard         0x0000000100002f8b main + 91 (main.cpp:10)
  27  com.yourcompany.PwrCard         0x0000000100002f24 start + 52
  
  Thread 1:
  0   libsystem_kernel.dylib          0x00007fff8c4c9e6a __workq_kernreturn + 10
  1   libsystem_pthread.dylib         0x00007fff900a8f08 _pthread_wqthread + 330
  2   libsystem_pthread.dylib         0x00007fff900abfb9 start_wqthread + 13
  
  Thread 2:: Dispatch queue: com.apple.libdispatch-manager
  0   libsystem_kernel.dylib          0x00007fff8c4ca662 kevent64 + 10
  1   libdispatch.dylib               0x00007fff872d243d _dispatch_mgr_invoke + 239
  2   libdispatch.dylib               0x00007fff872d2152 _dispatch_mgr_thread + 52
  
  Thread 3:
  0   libsystem_kernel.dylib          0x00007fff8c4c9e6a __workq_kernreturn + 10
  1   libsystem_pthread.dylib         0x00007fff900a8f08 _pthread_wqthread + 330
  2   libsystem_pthread.dylib         0x00007fff900abfb9 start_wqthread + 13
  
  Thread 4:
  0   libsystem_kernel.dylib          0x00007fff8c4c9e6a __workq_kernreturn + 10
  1   libsystem_pthread.dylib         0x00007fff900a8f08 _pthread_wqthread + 330
  2   libsystem_pthread.dylib         0x00007fff900abfb9 start_wqthread + 13
  
  Thread 5:
  0   libsystem_kernel.dylib          0x00007fff8c4c9e6a __workq_kernreturn + 10
  1   libsystem_pthread.dylib         0x00007fff900a8f08 _pthread_wqthread + 330
  2   libsystem_pthread.dylib         0x00007fff900abfb9 start_wqthread + 13
  
  Thread 6:
  0   libsystem_kernel.dylib          0x00007fff8c4c9e6a __workq_kernreturn + 10
  1   libsystem_pthread.dylib         0x00007fff900a8f08 _pthread_wqthread + 330
  2   libsystem_pthread.dylib         0x00007fff900abfb9 start_wqthread + 13
  
  Thread 7:
  0   libsystem_kernel.dylib          0x00007fff8c4c9e6a __workq_kernreturn + 10
  1   libsystem_pthread.dylib         0x00007fff900a8f08 _pthread_wqthread + 330
  2   libsystem_pthread.dylib         0x00007fff900abfb9 start_wqthread + 13
  
  Thread 8:
  0   libsystem_kernel.dylib          0x00007fff8c4c9e6a __workq_kernreturn + 10
  1   libsystem_pthread.dylib         0x00007fff900a8f08 _pthread_wqthread + 330
  2   libsystem_pthread.dylib         0x00007fff900abfb9 start_wqthread + 13
  
  Thread 9:
  0   libsystem_kernel.dylib          0x00007fff8c4c9e6a __workq_kernreturn + 10
  1   libsystem_pthread.dylib         0x00007fff900a8f08 _pthread_wqthread + 330
  2   libsystem_pthread.dylib         0x00007fff900abfb9 start_wqthread + 13
  
  Thread 10:
  0   libsystem_kernel.dylib          0x00007fff8c4c5a1a mach_msg_trap + 10
  1   libsystem_kernel.dylib          0x00007fff8c4c4d18 mach_msg + 64
  2   com.apple.CoreFoundation        0x00007fff89c64155 __CFRunLoopServiceMachPort + 181
  3   com.apple.CoreFoundation        0x00007fff89c63779 __CFRunLoopRun + 1161
  4   com.apple.CoreFoundation        0x00007fff89c630b5 CFRunLoopRunSpecific + 309
  5   com.apple.AppKit                0x00007fff8e9da16e _NSEventThread + 144
  6   libsystem_pthread.dylib         0x00007fff900a7899 _pthread_body + 138
  7   libsystem_pthread.dylib         0x00007fff900a772a _pthread_start + 137
  8   libsystem_pthread.dylib         0x00007fff900abfc9 thread_start + 13
  </code></pre>
  
  <p>I have my slot linked up with the returnPressed() signal of a lineEdit. I can't figure out for the life of me why this only happens for user-defined functions. Any help would be greatly appreciated. Thanks guys!</p>