title: Cannot access QMainWindow variables from child class
body: <p>I'm trying to set a variable that can be accessed from multiple children at the MainWindow (QMainWindow) level. The issue is whenever I try to access it from a child (or grandchild), I get a segmentation fault. </p>
  
  <p>Here's a mock up of the involved code:</p>
  
  <pre><code>//MainWindow.h
  ...
  public:
      int getVariable();
      void setVariable(int i);
  ...
  private:
      int globalInt;
      SomeWidget *myWidget;
  
  
  //MainWindow.cpp
  MainWindow::MainWindow(QWidget *parent) :
  QMainWindow(parent),
  ui(new Ui::MainWindow)
  {
      ...
      this-&gt;globalInt = 10;
      myWidget = new SomeWidget();
      myWidget-&gt;setParent(this);
      ....
  }
  int getVariable()
  {
      return this-&gt;globalInt;
  }
  void setVariable(int i)
  {
      this-&gt;globalInt = i;
  }
  ...
  
  
  
  //SomeWidget.cpp
  ...
  int x = (static_cast&lt;MainWindow*&gt;(this-&gt;parent()))-&gt;getVariable(); //Causes Segfault
  ...
  </code></pre>
  
  <p>I honestly have no idea what I'm doing wrong. I've tried creating a new MainWindow* pointer to the parent and casting it, I've tried making the "global" int public and directly accessing it, etc. etc. Any ideas what I need to do?</p>