poonam
poonam

Reputation: 810

python-form not displayed using show method

I am working with python plugins for QGIS.I have my main form as DlgQueryBuilder.py and another form as DlgDberror.py,which displays the error in the query.My DlgDberror.py contains following:

class DlgDbError(QtGui.QWidget, Ui_DlgDbError):
def __init__(self,e,parent):


    QtGui.QWidget.__init__(self)
    Ui_DlgDbError.__init__(self)
    self.setupUi(self)
    msg = "<pre>" + e.msg.replace('<','&lt;') + "</pre>"


    self.txtMessage.setHtml(msg)



@staticmethod
def showError(e, parent):

    dlg = DlgDbError(e,parent)
    dlg.show()

The call to this from DlgQueryBuilder.py is "DlgDbError.showError(e, self)" Everything goes smooth but when i try to run my main form DlgQueryBuilder.py,*DlgDberror.py* form is not shown.It dissapears within a second. dlg.show() should work rite??

Upvotes: 0

Views: 412

Answers (1)

gfortune
gfortune

Reputation: 2629

When showError exits, dlg is garbage collected and goes away which also destroys the underlying Qt objects and the dialog. I suspect you need to pass your dialog back to QGIS in some way so it can handle whatever is necessary with the dialog. So yes, show() works, but your program is destroying the dialog before it can do anything useful.

Perhaps you wanted exec_() instead? It will pop up the dialog and then block waiting for the user to close the dialog. This is known as a modal dialog. See http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qdialog.html

Upvotes: 1

Related Questions