[QGIS-Developer] Deactivate QgsRasterLayer CRS prompt

KOHLMANN Hannes H.KOHLMANN at ove.at
Wed Mar 21 10:13:11 PDT 2018


Hey Nyall!

Unfortunately, it doesn't... would that really be the only way to do this?
Or what could someone do wrong for these three lines of code to fail their purpose?

Hannes

-----Ursprüngliche Nachricht-----
Von: Nyall Dawson [mailto:nyall.dawson at gmail.com] 
Gesendet: Dienstag, 20. März 2018 22:53
An: KOHLMANN Hannes
Cc: qgis-developer at lists.osgeo.org
Betreff: Re: [QGIS-Developer] Deactivate QgsRasterLayer CRS prompt

On 21 March 2018 at 04:30, KOHLMANN Hannes <H.KOHLMANN at ove.at> wrote:
> Hello again!
>
>
>
> I do the following to add a QgsRasterLayer:
>
> l = QgsRasterLayer("/path/file.dat", "Density")
>
>
>
> Now I am struggling with a problem, that has somehow always the same 
> suggested solution in all fora, namely to get rid of the prompt that 
> appears
>
> when adding a QgsRasterLayer, by using:
>
> s = QSettings()
>
> oldValidation = s.value( "/Projections/defaultBehaviour" )
>
> s.setValue( "/Projections/defaultBehaviour", "useGlobal" ) # it 
> doesn’t matter what property to take, be it “useProject”, “useGlobal” 
> or “prompt” …
>
> … before adding the layer. But on my Linux environment, this does not 
> work – and also not on my collegue’s Windows system.
>
> Has there something changed with the usage of QSettings w.r.t. to its 
> usage in QGIS in the step from QGIS 2 to QGIS 3?
>

That should still work.

Try using QgsSettings instead (but I don't think this should be necessary):

s = QgsSettings()


Nyall


More information about the QGIS-Developer mailing list