Unsolved Calling __init__() in QObject subclasses
-
@KeirRice said in 'PySide2.QtCore.Signal' object has no attribute 'emit':
You also need to make sure that the init of the QObject is called. This is where pyside does the setup of the signals, trying to use the signal before setup wont work properly.
@KeirRice are you still around? :)
This answer is indeed correct for PySide2. However, I don't understand what you mean by "make sure that the
__init__
of the QObject is called". I do not define anydef __init__(self)
method of myclass someClass(QObject)
, and it works fine. Just deriving fromQObject
(or from any class) calls its__init__()
automatically.The only reason you need one in your example is because you want to do some other work there (connecting the signal in your case, which most people will do in the outside world, not in class's constructor). And then of course, like any derived class with its own
__init__
, you must callsuper().__init__()
.I see nothing at all special about defining/calling
__init__()
for the signal definition class. Do you have any comment (if you still exist :) )?[Edit: Locked as toxic and unproductive ~kshegunov]
-
@Denni-0
The question has absolutely nothing to do with whether you usesuper().__init__()
orbaseClass.__init__()
. Nothing to do withsuper()
, irrelevant to the question, which is why that user says it's important "You also need to make sure that the__init__
of the QObject is called" in a class which defines a signal. That is the only question being asked.I am well aware of your opinion on
super()
, since you express it in nearly every post you make. And I don't agree with you, and nor do plenty of others.you should be trying to figure out what you are doing wrong rather than telling them they are wrong.
Simply wrong. Did you read where I said
This answer is indeed correct for PySide2.
I do not define anydef __init__(self)
method of my class someClass(QObject), and it works fine.So it works fine without defining any
__init__()
method. And at no point did I say that poster was "wrong" in what he wrote, I merely asked him why he thinks it's important to do that. So don't tell me "I should be trying to figure out what you are doing wrong " when I'm not doing anything wrong.Nothing I have asked has anything to do with Python/PySide2 versus C++.
-
of you misinformed state something that is absolutely wrong as the truth is within python you ought almost never call
super().__init__()
and instead use the originalbaseClass.__init__(self)
instead.I don't agree, and nor do millions(?) of other Python3 programmers. But we'll have to move on, because discussing it gets us nowhere.
Let's ask this. Here are two definitions of a derived class:
First:
class DerivedClass(BaseClass): pass
Second:
class DerivedClass(BaseClass): def __init__(self): BaseClass.__init__(self)
Imagine that's it. There is nothing else, no other stuff. For example, there is no multi-inheritance, else the code would show it. Just that code. Not something else. (Note I've used
BaseClass.__init__()
, not evensuper().__init__()
, so we don't have to wonder aboutsuper()
).The question is: do these two behave any differently than each other, just as they stand? I say/claim/think/suspect they do not behave differently. If you do not define any
__init__()
in a derived class, it calls the base class's__init__()
automatically (can be verified in a debugger), so I claim there is no difference. If you think there is a difference (I don't know whether you do), can you supply some actual, concrete reference which says so and explains precisely what it is?That's is all my question really is.
-
@Denni-0
It's a very simple question. Nothing to do with slots, connections, potential issues,super
, 3 issues, or anything else. Not to do with what one might or might not consider better style. There are no "underlying wrapper that has been created by someone else".Without answering about anything else, are you saying
class DerivedClass(BaseClass): def __init__(self): BaseClass.__init__(self)
behaves differently from
class DerivedClass(BaseClass): pass
? I'd like to know. If so, could you provide a reference so I can read up. Thanks.
-
@Denni-0 said in 'PySide2.QtCore.Signal' object has no attribute 'emit':
troll question
I never ask "troll" questions. Life is too short.
In my example I don't particularly intend
BaseClass
to be derived fromQObject
, else I would have stated that explicitly. Though it could be, if that makes any difference to the answer.I have since looked around and seen much code (both Qt and non-Qt) which does indeed not bother to declare an explicit
__init__()
constructor in a derived class if it does not need to do anything other than class the base class constructor. At the moment from reading around I am happy that the default behaviour of a derived class with no explicit__init__()
, which is to call base class__init__()
automatically, suffices. Unless you have a reference to the contrary? -
@Denni-0 said in 'PySide2.QtCore.Signal' object has no attribute 'emit':
BTW if you had come to me respectfully with your question I would have been more than happy to have explained this to you in that manner but you chose to be basically disrespectful in your approach
because you simply cannot comprehend the basic coding principles of Object Oriented programming let alone Function Oriented programming and I would suggest you go back to linear coding as you will cause a lot less harm with your programs.
OK, if that's how you feel and speak let's call it a day. Nobody other than you speaks to people like this in this forum.
-
@Denni-0
I have been careful to be polite in everything I have ever posted in response to you, always saying you have your opinions and others have theirs. You are just rude and abusive. Nobody other than you accuses others of lying, trolling, or the endless stream of insults you throw in your responses. I guess in all my career I have never come across anyone like you in a professional or technical environment. I still remember the first post I saw from you where you announced that @Pablo-J-Rogina was a "troll" and you would have him banned. It's a shame you are allowed to do so.We have nothing more to say to each other.
-
@JonB said in Calling __init__() in QObject subclasses:
I guess in all my career I have never come across anyone like you in a professional or technical environment.
I have. I suppose you've just occupied a less hostile time and place in the universe.
I still remember the first post I saw from you where you announced that @Pablo-J-Rogina was a "troll" and you would have him banned.
Heh, that's actually rather funny.
It's a shame you are allowed to do so.
Personally, I'm very lenient, less personally - willfully treading on thin ice is going to get you into the freezing water, sooner or later.
-
@kshegunov said in Calling __init__() in QObject subclasses:
get you into the freezing water
it is beneficial for your health
-
@LeLev said in Calling __init__() in QObject subclasses:
it is beneficial for your health
Ordinarily I'd agree, but the deadly sniffles is afoot, so I'd advise against it.
-
@JonB said in Calling __init__() in QObject subclasses:
I don't understand what you mean by "make sure that the
__init__
of the QObject is called". I do not define anydef __init__(self)
method of myclass someClass(QObject)
, and it works fine. Just deriving fromQObject
(or from any class) calls its__init__()
automatically.While I don't have experience with PySide, I read @KeirRice's comment as saying: "IF you implement a custom
__init__()
method, THEN remember to explicitly call the base implementation of__init__()
."Does that sound right to you?
@kshegunov said in Calling __init__() in QObject subclasses:
the deadly sniffles
That's the first time I've heard it called that. It's a disturbingly cute name.
-
@Denni-0 said in Calling __init__() in QObject subclasses:
@kshegunov the interesting thing I found is that JonB did not feel he was doing anything impolite as he feels every unrelated completely off topic manipulative comment he has made was simply him being polite.
What he feels or doesn't feel is beside the point. He asked an acceptable question, and even if you think it may've been manipulative, well sorry, you're just gonna have to eat it.
Which is ironic because that by nature is not a polite thing to do however I have no problems with giving back what I am given which is to say try to bully me and I get right in your grill
I don't grill. I have a very thick skin that's been growing thicker by merit of my living in eastern Europe. I don't care about political correctness, nor do I employ it, nor do I agree with it. I call it as I see it, if you don't like that then I suggest refraining from talking to me. Don't try to test the patience of the moderators group, we are decent enough bunch and allow a lot of freedom, but that doesn't mean disruptive aggressive behaviour is going to be tolerated for too long a time. This is not a discussion, mind you, I'm telling you how things are.
I am currently trying to find out what their definition of trolling is.
Trying to hijack the technical discussion on multiple occasions by arguing moderators' decisions is one form of trolling. Everyone is entitled to their opinion, but that doesn't mean everyone else is entitled to listening to their opinion, like with the "entitled" tone in the second part of your post. If you think this is some kind of a democracy where your opinion of what's trolling weighs more than say @SGaist's, then I must assure you you're sorely mistaken. Blatantly disrespectful tone and going around telling everybody you're smart and they're dumb doesn't fly well, neither in earning respect, nor in soliciting support for your point.
-
@Denni-0 said in Calling __init__() in QObject subclasses:
Yeah and your post was highly technical and spot on the original topic which is Calling init() in QObject subclasses --- NOT Best not to point fingers when you are extremely guilty yourself. Further its an extreme exaggeration "on multiple occasions?" or your math is really bad
Are we arguing? I told you already, this is not a discussion.
-
@Denni-0
Since we are talking facts.
Im the most friendly mod here and frankly, you are the first troll-like person i have seen here.I understand you feel deeply about__INIT__ but you resort to name-calling and aggressive behavior
and insist that our long term users are trolling.So can you please dial it down a notch?
-
@Denni-0 said in Calling __init__() in QObject subclasses:
okay so you have ended this thread then?
Yes, metaphorically and literally.
Also I am assuming by your statements that you have made earlier that you have moderator power otherwise you would not be so abusive yourself?
When you assume ... and you know the rest. I've openly said already I am a moderator.