title: Connecting qml-signals to Qt
body: <p>I'm trying to use a qml-grid view in my code. I'm trying to couple it with my C++ code.
  I've dynamically created a list view model and passed across the qml file. It works fine.
  However, I'm facing trouble when I want to connect a Qml signal to Qt/c++ code. I've handled mouseArea in my Qml-rectangle and emitting a signal from there.</p>
  
  <p>I'm trying to connect to the signal as follows:</p>
  
  <pre><code>QDeclarativeView *pQMLContainer = NULL;
  TempWidget *pTemp = new TempWidget();
  pQMLContainer = new QDeclarativeView(pTemp);
  pQMLContainer-&gt;setResizeMode(QDeclarativeView::SizeRootObjectToView);
  pQMLContainer-&gt;rootContext()-&gt;setContextProperty("imgModel", createModel() );
  pQMLContainer-&gt;setSource(QUrl("../Temp/qml/gridview-example.qml"));
  QObject *rootObject = dynamic_cast&lt;QObject*&gt;pQMLContainer-&gt;rootObject();
  QObject::connect(rootObject, SIGNAL(keyPressed()), pTemp, SLOT(onKeyPressed()));
  </code></pre>
  
  <p>When the connect statement runs, I get an error: cannot connect to "null" object.
  On debugging, I found I could never get "rootObject" as a valid pointer.
  Where am I going wrong?</p>
  
  <p>Thanks</p>