2

I'm trying to work through this answer in the QGIS (2.14) Python console to understand, ultimately, how to iterate over layers and print them with a template.

When I run the following code block.

I get a NameError that QDomDocument() is undefined.

myComposition = QgsComposition(myMapRenderer)
myFile = os.path.join(os.path.dirname(__file__), 'MMR_Template.qpt')
myTemplateFile = file(myFile, 'rt')
myTemplateContent = myTemplateFile.read()
myTemplateFile.close()
myDocument = QDomDocument()

Possibly related (can split into a separate question) I also get the warning DeprecationWarning: QgsComposition constructor is deprecated but can find nothing about this warning on Google.

  • did you add from qgis.PyQt.QtXml import QDomDocument – Matthias Kuhn Dec 15 '16 at 23:47
  • Nope. Will try tomorrow – raphael Dec 15 '16 at 23:47
  • @MatthiasKuhn that worked. Any idea about the deprecation warning? – raphael Dec 16 '16 at 21:53
  • @MatthiasKuhn feel free to turn your comment into an answer – raphael Dec 28 '16 at 15:38
2

From this comment, adding the following line to the console script resolved this issue in 2.14 to 2.18.2

from qgis.PyQt.QtXml import QDomDocument

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.