I can not sub class QAbstractCameraController in PyQt3D. Is this a bug?
class FemapCameraController(QAbstractCameraController):
def __init__(self, rootEntity):
super(FemapCameraController, self).__init__(rootEntity)
...
TypeError: PyQt5.Qt3DExtras.QAbstractCameraController cannot be instantiated or sub-classed
Related
In the 1994 book Design Patterns: Elements of Reusable Object-Oriented Software by the "Gang of Four", I noticed in the C++ code examples that all methods are either declared as public or protected (never as private) and that all attributes are declared as private (never as public or protected).
In the first case, I suppose that the authors used protected methods instead of private methods to allow implementation inheritance (subclasses can delegate to them).
In the second case, while I understand that avoiding public and protected attributes prevents breaking data encapsulation, how do you do without them if a subclass need access a parent class attribute?
For example, the following Python code would have raised an AttributeError at the get_salary() method call if the _age attribute was private instead of protected, that is to say if it was named __age:
class Person:
def __init__(self, age):
self._age = age # protected attribute
class Employee(Person):
def get_salary(self):
return 5000 * self._age
Employee(32).get_salary() # 160000
I have finally found out an obvious solution by myself: redeclaring the private attribute of the parent class in the subclass:
class Person:
def __init__(self, age):
self.__age = age # private attribute
class Employee(Person):
def __init__(self, age):
self.__age = age # private attribute
def get_salary(self):
return 5000 * self.__age
Employee(32).get_salary() # 160000
I try to pass a generic type to sub , but get error.
I constraint with base class then pass son class and not working ,am I misunderstood?
Main:
Private Sub GenericTypeTest_Load
Dim tA As New TypeA
Dim tCon As New TypeContainer(of TypeA)
subTest(tCon) 'error here
End Sub
Class:
Public Class TypeBase
End Class
Public Class TypeA : Inherits TypeBase
End Class
Public Class TypeContainer(of T As {TypeBase, New})
End Class
Error message :
Type TypeContainer(Of TypeA) cannot convert to TypeContainer(Of TypeBase)
Oh ,thank for your help and sorry for my bad English and phone typesetting.
The fact that TypeA inherits TypeBase does not mean that TypeContainer(Of TypeA) inherits TypeContainer(Of TypeBase). You can only pass an argument to subTest that is, inherits or implements the type of the parameter.
Show the declaration of subTest and maybe I can be more specific.
I want to inherit #classmethod of class BaseModel(object)
How to inherit or override the #classmethod in our custom module ?
I just ran into this today :)
You can extend it in a couple of ways. It depends if you really need to extend BaseModel or if you need to extend a specific sub class of BaseModel.
Sub Class
For any sub class you can inherit it as you would normally:
from odoo import api, fields, models
class User(models.Model):
_inherit = 'res.users'
#classmethod
def check(cls, db, uid, passwd):
return super(User, cls).check(db, uid, passwd)
Extend BaseModel Directly
In the case of BaseModel itself you are going to need to monkey patch:
from odoo import models
def my_build_model(cls, pool, cr):
# Make any changes I would like...
# This the way of calling super(...) for a monkey-patch
return models.BaseModel._build_model(pool, cr)
models.BaseModel._build_model = my_build_model
I am working on vb.net for an MT2070 scanner. I have referenced objects in other classes before, but not when that other class is "Inheriting" something. How do I reference something in a class that inherits attributes from another class?
I have this class:
Public Class MainScreen
Inherits ListScreen
Sub AddToInventory(ByVal barcode As String)
'...code here
end sub
And I would like to reference the object "AddToInventory" in another class. I thought this would work:
Public Class MainForm
Inherits ListForm
Sub RunTest
Dim w As MainScreen = New MainScreen
w.AddToInventory("10010")
But I get this Error: Argument not specified for parameter 'listform' of 'public sub new(listform as listform)'
Please advise, what am I missing? How do I reference "AddToInventory"?
Your error has got nothing to do with inheritance, nor with your AddToInventory method. You are simply failing to call the constructor of MainScreen with its required arguments (apparently listform is required).
Thanks Konrad - your insight led me to the answer. I needed just a small modification:
Public Class MainForm
Inherits ListForm
Sub RunTest
Dim w As MainScreen = New MainScreen(me)
w.AddToInventory("10010")
VB.Net2005
Simplified Code:
MustInherit Class InnerBase(Of Inheritor)
End Class
MustInherit Class OuterBase(Of Inheritor)
Class Inner
Inherits InnerBase(Of Inner)
End Class
End Class
Class ChildClass
Inherits OuterBase(Of ChildClass)
End Class
Class ChildClassTwo
Inherits OuterBase(Of ChildClassTwo)
End Class
MustInherit Class CollectionClass(Of _
Inheritor As CollectionClass(Of Inheritor, Member), _
Member As OuterBase(Of Member))
Dim fails As Member.Inner ' Type parameter cannot be used as qualifier
Dim works As New ChildClass.Inner
Dim failsAsExpected As ChildClassTwo.Inner = works ' type conversion failure
End Class
The error message on the "fails" line is in the subject, and "Member.Inner" is highlighted. Incidentally, the same error occurs with trying to call a shared method of OuterBase.
The "works" line works, but there are a dozen (and counting) ChildClass classes in real life.
The "failsAsExpected" line is there to show that, with generics, each ChildClass has its own distinct Inner class.
My question: is there a way to get a variable, in class CollectionClass, defined as type Member.Inner? what's the critical difference that the compiler can't follow?
(I was eventually able to generate an object by creating a dummy object of type param and calling a method defined in OuterBase. Not the cleanest approach.)
Edit 2008/12/2 altered code to make the two "base" classes generic.
Dim succeeds as OuterBase.Inner
.net does not have C++'s combination of template classes and typedefs, which means what you are trying to do is not possible, nor does it even make sense in .net.
ChildClass.Inner and SomeOtherChildClass.Inner are the same type. Here's a short but complete program to demonstrate:
Imports System
MustInherit Class InnerBase
End Class
MustInherit Class OuterBase
Class Inner
Inherits InnerBase
End Class
End Class
Class ChildClass
Inherits OuterBase
End Class
Class OtherChildClass
Inherits OuterBase
End Class
Class Test
Shared Sub Main()
Dim x as new ChildClass.Inner
Dim y as new OtherChildClass.Inner
Console.WriteLine(x.GetType())
Console.WriteLine(y.GetType())
End Sub
End Class
The output is:
OuterBase+Inner
OuterBase+Inner
What were you trying to achieve by using "parameterised" nested classes? I suspect that either it wouldn't work how you'd want it to, or you can achieve it just by using OuterBase.Inner to start with.
Now if each of your child classes were declaring their own nested class, that would be a different situation - and one which generics wouldn't help you with.