Qt XML Patterns File System Example: Do not bind to a null node index
authorTopi Reiniƶ <topi.reinio@nokia.com>
Wed, 4 Jul 2012 11:38:58 +0000 (13:38 +0200)
committerQt by Nokia <qt-info@nokia.com>
Wed, 11 Jul 2012 21:40:13 +0000 (23:40 +0200)
Adds a check for validity of the file node index before running an
XQuery.

In evaluateResult(), QXmlQuery binds to a QXmlNodeModelIndex variable
without checking if it's valid. This causes an assert to trigger if
the default directory that the example tries to open does not exist.
In this case, m_fileNode has the default (null) value when
evaluateResult() is invoked on QComboBox::currentIndexChanged()
signal.

Task-number: QTBUG-26081
Change-Id: I03c39939b57fcf658527ce3110fdc30d204de520
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@nokia.com>
examples/xmlpatterns/filetree/mainwindow.cpp

index 83c3ebf..3116305 100644 (file)
@@ -94,7 +94,7 @@ void MainWindow::on_queryBox_currentIndexChanged()
 //! [3]
 void MainWindow::evaluateResult()
 {
-    if (queryBox->currentText().isEmpty())
+    if (queryBox->currentText().isEmpty() || m_fileNode.isNull())
         return;
 
     QXmlQuery query(m_namePool);