[Qgis-developer] Null Value in QLineEdit

Enrico Fiore enricofiore at libero.it
Sat Apr 4 03:01:06 PDT 2015


Hi,
thanks for your answer.

I have done others tests, whit your suggestions

Il 04/04/2015 01:21, Nikhil Murarka ha scritto:
> try:
>
> if myDialog.findChild(QLineEdit,"cod_direzione").text() == "":
> myDialog.findChild(QLineEdit,"cod_direzione").setText("A")
> else:
>  myDialog.findChild(QLineEdit,"cod_direzione").setText("NOT NULL")
>
> I think the text is not empty string intially because it work for me.
I tried with the else clause, and you are right  it is like if the field 
is not empty.
But it is strange because the form appear when I edit a new point, whit 
all the form slots empty.

The layer is a Multipoint in a Postgresql database, the field is a 
varchar(1) .

the field is recognised empty if I write this code:

   if myDialog.findChild(QLineEdit,"des").text() == u"NULL":
     myDialog.findChild(QLineEdit,"des").setText("A")

>
> Also where are you defining this statement ? -some callback function 
> or  __init__
I call the .py file inside the layer properties
>
>
> Can you post the complete function ?

from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
from qgis.gui import *

def formOpen(dialog, layerid, featureid):
     myDialog = dialog
     global myDialog
     # Riferimento ai bottoni
     buttonBox = dialog.findChild(QDialogButtonBox, "buttonBox")

     # Disconnessione del segnale che QGIS ha automaticamente associato 
alla zona dei pulsanti
     buttonBox.accepted.disconnect(myDialog.accept)
     # Connessione del nostro segnale
     buttonBox.accepted.connect(validate)
     buttonBox.rejected.connect(myDialog.reject)


def validate():
     # cod_direzione default = A
     if myDialog.findChild(QLineEdit,"des").text() == "":
         myDialog.findChild(QLineEdit,"des").setText("A")
     else:
          myDialog.findChild(QLineEdit,"des").setText("N")


More information about the Qgis-developer mailing list