9

I'm trying to write a python plugin for QGis. I'd like to debug some DB queries and I need a way to display the result.

I thought about using a popup to display it, but I don't know how to show a popup from inside a python plugin.

Can anyone suggest me how to do that?

1

3 Answers 3

10

Finally I solved this way:

def printMsg(self,msg):
    QMessageBox.information(self.iface.mainWindow(),"Debug",msg)

I don't know if it's the best way to go, but it seems to work fine.

0
0

I've ended up using the print out messages way as well except I set up a variable (global?) that I can turn off when I release the plugin, PluginMsgTxt is the name of the plugin - which I use for info messages, warnings etc as well

InDebugMode = True

def debugMsg(self, InDebugMode, PluginMsgTxt, msg):
   #this will print nothing if InDebugMode is false
   if InDebugMode:
       iface.messageBar().pushMessage("MAINDEBUG: ", msg, level=Qgis.Info, duration = 1)
0

Instead of pop-ups, I recommend using the First Aid plugin.

Provides Python debugger and replaces the default Python error handling in QGIS with a more sophisticated handler that allows more thorough inspection or the Python error: browse the frames, view variables, see source code or even execute Python code within the context of the error.

Your Answer

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

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