I'm looking for a way to execute a python script upon exporting a print composer. Specifically, I want it to run once for each page exported. (logging some data and possibly updating a database).

So far I've created a custom expression that writes a log to a file and returns an empty string. I created an off-page label that runs the expression.

The problem is, this runs every time the page refreshes so it's running a bunch just paging through the atlas.

Trying to get it to run only on export, I put it in the 'export filename' field but that too runs every time the page refreshes.

Is there some way I can either force it to only run on export, or in the python code detect if the page is being exported before running?

edit: here's the test code I'm running so far:

def logTest(logitem):
    global logFileName
    f = open(logFileName, 'a')

@qgsfunction(args='auto', group='Territory')
def postData(postItem, feature, parent):
    return u''

and my expression to test it is simply:

  • Doesn't seem possible. Created a feature request here: hub.qgis.org/issues/15726
    – J M
    Oct 23, 2016 at 6:31
  • Could you make a workaround based on catching the QgsComposerMap.preparedForAtlas() signal? Nov 3, 2016 at 15:33
  • Thanks for your suggestion. I don't know how to do that but I will research.
    – J M
    Nov 3, 2016 at 22:39
  • @JesseMcMillan Please post the feature request as an answer.
    – underdark
    Dec 4, 2017 at 18:34

1 Answer 1


Not currently possible. Feature request here: https://issues.qgis.org/issues/15726

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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