[Qgis-developer] Cannot inherit from QgsVectorLayer in plugin on Windows

Radim Blazek radim.blazek at gmail.com
Mon Aug 28 06:28:51 EDT 2006


Hi,
I dont think this is the case because I have compiled
everything with the same libraries and especially
it does not crash, it fails to load the library!
QLibrary.load() fails, that means before any piece of
my code is executed.
The class does not need to be used at all. It fails to load
the plugin if I compile into the plugin this class:

BiogeoSource::BiogeoSource ( QString n, QString p, QString l )
    : QgsVectorLayer ( n, p, l) {};
BiogeoSource::~BiogeoSource(){}

Radim

On 8/28/06, Mateusz Loskot <mateusz at loskot.net> wrote:
> Tim Sutton wrote:
> > Hi
> >
> > I wonder if its anything to do with the win dll boundary issue :
> >
> > http://msdn2.microsoft.com/en-us/library/ms235460.aspx
> >
>
> I assume Tim is right, however the article above does not
> mention similar situation that likely occurs in QGIS/plugins on Windows.
>
> Generally, inheriting from class in external DLL is a bad idea
> on Windows, unless developer will promise that the base class
> does not allocate anything and return it outside.
> For example
>
> // a.dll
> struct B {};
>
> struct A
> {
>    // Ownership transfered to the caller
>    B* getB()
>    {
>       B* p = new B();
>       return p;
>    }
> };
>
> // c.dll
> struct C : public A
> {
>    void foo()
>    {
>       B* p = getB();
>       //...
>       delete p; // BOOM!!! DLL boundaries crossed
>    }
> };
>
> Although, I'm not sure if QgsVectorLayer does apply to this situation.
> May be there are some resources allocated in constructor of the base
> class, and then they cross DLL boundaries. That would be likely unsafe
> too, on Windows.
>
> But I think it may be necessary to track where the crash
> occurs, to know what's the exact reason.
>
> Cheers
> --
> Mateusz Loskot
> http://mateusz.loskot.net
> _______________________________________________
> Qgis-developer mailing list
> Qgis-developer at lists.qgis.org
> http://lists.qgis.org/cgi-bin/mailman/listinfo/qgis-developer
>



More information about the Qgis-developer mailing list