title: Switching the Source of a QDeclarativeView
body: <p>First question here, so bear with me. </p>
  
  <p>I have been trying to create a view on a QMainWindow using a QDeclarativeView as the canvas, but whenever I try to switch the source of the QDeclarativeView my program segfaults and I frankly have no idea why, or how to fix it. </p>
  
  <p>Here is my swapView() function.</p>
  
  <pre><code>void MainWindow::swapView(int view)
  {
   switch (view)
   {
      case 0:
          cout &lt;&lt; "Switching to Slideshow..." &lt;&lt; endl;
          this-&gt;setSource("Slideshow.qml");
          break;
      case 1:
          cout &lt;&lt; "Switching to Main Canvas..." &lt;&lt; endl;
          this-&gt;setSource("Test.qml");
          cout &lt;&lt; "Successfully switched to Main Canvas!" &lt;&lt; endl;
          break;
   }
  }
  </code></pre>
  
  <p>Here is the setSource() method that it is calling:</p>
  
  <pre><code>void MainWindow::setSource(QString fileName)
  {
      this-&gt;ui-&gt;declarativeView-&gt;setSource(QUrl::fromLocalFile("Test.qml"));
  }
  </code></pre>
  
  <p>I tried replacing the code above with the code below, and it gets rid of the segfault, but each window opens in a separate window instead of just replacing the view on the QDeclarativeView. </p>
  
  <pre><code>void MainWindow::setSource(QString fileName)
  {
      QDeclarativeView *view = new QDeclarativeView;
      view-&gt;setSource(QUrl::fromLocalFile(fileName));
      ui-&gt;declarativeView = view;
      ui-&gt;declarativeView-&gt;show();
  }
  </code></pre>
  
  <p>If anyone has any input on what I'm doing wrong (I'm sure it's something stupid), please let me know... </p>
  
  <p>Thanks.</p>