[Qgis-developer] Null Value in QLineEdit

Nikhil Murarka nikhilmurarka14 at gmail.com
Sat Apr 4 06:12:31 PDT 2015


I guess this form is populated when you add new feature to layer. Your
PostgreSQL database schema should define 'default' value as ''

abc varchar(1) default ''

if you don't define the default value qgis make it 'NULL'

Not exactly sure but this should solve the problem

On Sat, Apr 4, 2015 at 6:01 AM, Enrico Fiore <enricofiore at libero.it> wrote:

> 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")
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20150404/449301de/attachment-0001.html>


More information about the Qgis-developer mailing list