title: accessing a reference variable terminates the program
body: <p>My program terminates when I refer to the properties of the referenced variable src_.
  The main idea of the code is that the MainWindow class calls SettingsWindow class to show some settings. There are also two additional classes which take care of the saved settings, those are ConfigSource and the ConfigUpdater. src_ is defined as a referenced variable inside ConfigUpdater. Here's the code:</p>
  
  <p>inside MainWindow:</p>
  
  <pre><code>MainWindow::MainWindow(QWidget *parent) :
      QMainWindow(parent),
      ui(new Ui::MainWindow)
  {
      ui-&gt;setupUi(this);
  
      ConfigSource cfg;
  
          settings = new SettingsWindow(cfg,this);
  
          settings-&gt;print_config(cfg.config());
  ...
  </code></pre>
  
  <p>SettingsWindow Header and source:</p>
  
  <pre><code>#ifndef SETTINGSWINDOW_H
  #define SETTINGSWINDOW_H
  
  #include &lt;QMainWindow&gt;
  #include &lt;QModelIndex&gt;
  
  #include &lt;QSignalMapper&gt;
  #include &lt;QRadioButton&gt;
  #include &lt;QSpinBox&gt;
  #include &lt;QTimer&gt;
  
  #include "cameracommands.h"
  
  struct Config
  {
      /* General Options */
      QString general_key_lock;
      QString general_back_light;
  };
  
  class ConfigSource 
  {
      public:
  
      ConfigSource() {
          qDebug() &lt;&lt; "inside configSource :))";
          config_.general_aperture_control   = "Reset";
          config_.general_automatic_exposure = "Full Auto";
  
      }
  
      Config config() const {return config_;}
  
      void setConfig(const Config&amp; cfg) {config_ = cfg;}
  
  //        Config config_;
      private:
      Config config_;
  };
  
  class ConfigUpdater : public QObject
  {
      Q_OBJECT
  public:
      ConfigUpdater(ConfigSource&amp; src) : src_(src) {}
  
  public slots:
  
      void apply () {src_.setConfig(tempConfig_);}
      void cancel() {tempConfig_ = src_.config();}
  
  public:
  
      void updateGeneralBackLight(QString s)             {tempConfig_.general_back_light         = s; qDebug() &lt;&lt; "BackLight updated :)";}
      void updateGeneralKeyLock(QString s)               {tempConfig_.general_key_lock           = s; qDebug() &lt;&lt; "KeyLock updated :)";}
  
      Config tempConfig_;
      ConfigSource&amp; src_;
  };
  
  //----------------------------
  
  namespace Ui {
      class SettingsWindow;
  }
  
  class SettingsWindow : public QMainWindow
  {
      Q_OBJECT
  
  public:
      explicit SettingsWindow(ConfigSource &amp;src, QWidget *parent = 0);
  
      ~SettingsWindow();
  
      void print_config(Config cfg);
  
  signals:
      void clicked(const QString &amp;text);
      void sendToPLC(QByteArray );
  
  public slots:
      void updateGeneralBackLight();
      void updateGeneralKeyLock();
  
  private:
  
      void set_mappings();
  
      Ui::SettingsWindow *ui;
      ConfigUpdater      *config_updater;
  };
  
  #endif // SETTINGSWINDOW_H
  </code></pre>
  
  <p>Settings source file</p>
  
  <pre><code>SettingsWindow::SettingsWindow(ConfigSource &amp;src, QWidget *parent) :
      QMainWindow(parent),
      ui(new Ui::SettingsWindow)
  {
      /* initializations */
      ui-&gt;setupUi(this);
      config_updater = new ConfigUpdater(src);
  </code></pre>
  
  <p>This part is critical, when I try to access src_ from apply and cancel slots, program terminates, example:</p>
  
  <pre><code>void SettingsWindow::on_pushButton_3_clicked() //apply
  {
      qDebug() &lt;&lt; "Apply Button";
  
      print_config(config_updater-&gt;src_.config());
      config_updater-&gt;apply();
      print_config(config_updater-&gt;src_.config());
  }
  
  void SettingsWindow::print_config(Config config)
  {
      qDebug() &lt;&lt; config.general_key_lock;
      qDebug() &lt;&lt; config.general_back_light;
  }
  
  void SettingsWindow::on_sendToMainButton_clicked() /* cancel */
  {
     print_config(config_updater-&gt;tempConfig_);
  
     config_updater-&gt;cancel();
  
     print_config(config_updater-&gt;tempConfig_);
  
     print_config(config_updater-&gt;src_.config_);
  }
  </code></pre>
  
  <p>Though, printing the _tempconfig variable works fine! I removed some button slots from the header file for simplicity.</p>
  
  <p>I would thank if you show me how to solve this bug : )</p>