![]() |
Re: PyQt Chaning multiple Objects attributes at once
Quote:
Code:
tempPushButton = QtGui.QPushButton() |
Re: PyQt Chaning multiple Objects attributes at once
Quote:
|
Re: PyQt Chaning multiple Objects attributes at once
Quote:
The Pythonic way rocks, so much easier when you know how :D |
Re: PyQt Chaning multiple Objects attributes at once
I assume list comprehensions aren't used to keep things simple/terse?
|
Re: PyQt Chaning multiple Objects attributes at once
Quote:
|
Re: PyQt Chaning multiple Objects attributes at once
Quote:
I can already hear the question - but then I need to create an array and append all of them... yuck, that's no better than the original ! But before I address that valid concern, let's let's dig a little deeper into the topic of Python-style garbage collection. Take a look at this: Code:
// C++This also explains why you don't get a segfault in your original example - by calling the layout's addWidget before the QPushButton you created a reference that prevents garbage collection. Without this, if you came back to it after the original QPushButton pointer went out of scope (or the reference disappeared for whatever ownership reason), you would get a big fat segfault because (unlike in C++) the underlying object is no longer there. So the alternative solution to local variables (which are ugly if you have many objects) is to specify parents in the constructor, creating the necessary reference to avoid garbage collection (i.e. mylist.append(QPushButton(parent))). Usually you create enough references inadvertently (like here with addWidget, or QObject voodoo that happens behind the scenes) for garbage collection/ownership not to mess you up, but sooner or later, especially in applications with multiple intertwined classes, you *will* run into segfaults or weirdness because of this. Seems we got into deep water here, but the idea is not to get surprised when you meet your first segfaults and know where to look for trouble spots :) |
Re: PyQt Chaning multiple Objects attributes at once
Quote:
EDIT: just for the sake of completeness: Code:
[[led.setChecked(self.ledState) for led in row] for row in self.ledArray] |
| All times are GMT. The time now is 22:24. |
vBulletin® Version 3.8.8