title: Qt Segfault - Non-coding error
body: <p>I was creating a very simple class as part of a much larger project. The class was as simple as:</p>
  
  <pre><code>class Login : public QDialog
  {
      Q_OBJECT
      private:
          QLineEdit* txtUser;
          QLineEdit* txtPass;
          void setupUI();
      public:
          Login(QWidget* parent = 0);
  };
  </code></pre>
  
  <p>When attempting to create the <code>setupUI()</code> function the line <code>txtUser = new QLineEdit;</code> would crash. I tried changing a lot of things and nothing would help. I took the project, copied it, and removed everything except this class and a <code>main.cpp</code> and there was no error. I returned to my original project (reloading Qt Creator) and it continued to fail. I began commenting out random self-written header files from the main in case of some sort of conflict. After commenting out each one, I would re-compile and run. Each time it would continue to fail. After the last one, it worked. Then, I re-enabled everything and it ran great once again.</p>
  
  <p>So, my question is, what could cause a segfault of this type with such simple code? In addition what might my changes have done to fix it if no code was changed? Basically, if I get this problem to ever occur again and I'm sure there are no errors, what steps should I take?</p>
  
  <p>Please keep in mind I am using Qt and Qt Creator within Windows.</p>
  
  <p>Finally, for the sake of completion, here is the code within <code>setupUI()</code>:</p>
  
  <pre><code>void Login::setupUI()
  {
      QVBoxLayout* main = new QVBoxLayout;
      QHBoxLayout* userBox = new QHBoxLayout;
      QHBoxLayout* passBox = new QHBoxLayout;
      txtUser = new QLineEdit;
      txtPass = new QLineEdit;
      userBox-&gt;addWidget(new QLabel("User Name:"));
      userBox-&gt;addWidget(txtUser);
      passBox-&gt;addWidget(new QLabel("Password:"));
      txtPass-&gt;setEchoMode(QLineEdit::Password);
      passBox-&gt;addWidget(txtPass);
      main-&gt;addLayout(userBox);
      main-&gt;addLayout(passBox);
      setLayout(main);
  }
  </code></pre>