I wish to create a virtual field that will automatically update when new attributes are added; the equation is for working out the 10 figure grid reference of a point shapefile in SpatiaLite:

floor(((round($x)/100000)-floor(round($x)/100000))*100000) || floor(((round($y)/100000)-floor(round($y)/100000))*100000)

However, some of the rows appear with 'NULL' values - when I tried making a new field without virtual field selected they all came with a value but then this would not update when new points were added.

How can I fix this?

Also, this SpatiaLite layer will be shared across many projects, therefore will the virtual field be updated within each project?

  • 2
    I changed the type from integer to text (string) and this has seemed to work now Nov 5, 2019 at 11:55
  • As it should be another question I put this as a comment. If you add a virtual field in a QGIS project it will be available only in this specific project (virtual field definition are recorded in the .qgs document, not in the database or data source) so adding the layer in another qgis project will require you to recreate the virtual field (maybe drag and drop between project will work ?). If you want to have this field in all project you may try to create an editable view in spatialite and use this view in your qgis project
    – J.R
    Nov 20, 2019 at 15:51

1 Answer 1


Change type from integer to Text(string)

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.