signals-slots

Is it safe to emit signal passing QObject pointer as parameter right before the passed object is going to be destroyed?

元气小坏坏 提交于 2020-12-08 16:09:06
问题 Lets consider this simple example: Class Emitter: public QObject { ... signal: surfaceDestroyed(QObject*); public: void emittingMethod(QObject* surface) { emit surfaceDestroyed(surface); delete surface; } } I have a queued connection for this case connect(emitterObject, SIGNAL(surfaceDestroyed(QObject*), receiverObject, SLOT(onSurfaceDestroyed(QObject*)), Qt::QueuedConnection); In onSurfaceDestroyed method the received QObject is dereferenced and used So the question is how safe this code is?

Is it safe to emit signal passing QObject pointer as parameter right before the passed object is going to be destroyed?

六眼飞鱼酱① 提交于 2020-12-08 16:04:14
问题 Lets consider this simple example: Class Emitter: public QObject { ... signal: surfaceDestroyed(QObject*); public: void emittingMethod(QObject* surface) { emit surfaceDestroyed(surface); delete surface; } } I have a queued connection for this case connect(emitterObject, SIGNAL(surfaceDestroyed(QObject*), receiverObject, SLOT(onSurfaceDestroyed(QObject*)), Qt::QueuedConnection); In onSurfaceDestroyed method the received QObject is dereferenced and used So the question is how safe this code is?

PyQt Event when a variable value is changed

给你一囗甜甜゛ 提交于 2020-08-07 05:19:31
问题 I have a variable t t = 0 I want to start an event whenever t value is changed. How ? There's no valuechanged.connect properties or anything for variables... 回答1: For a global variable, this is not possible using assignment alone. But for an attribute it is quite simple: just use a property (or maybe __getattr__/__setattr__). This effectively turns assignment into a function call, allowing you to add whatever additional behaviour you like: class Foo(QWidget): valueChanged = pyqtSignal(object)

PyQt Event when a variable value is changed

不羁的心 提交于 2020-08-07 05:18:32
问题 I have a variable t t = 0 I want to start an event whenever t value is changed. How ? There's no valuechanged.connect properties or anything for variables... 回答1: For a global variable, this is not possible using assignment alone. But for an attribute it is quite simple: just use a property (or maybe __getattr__/__setattr__). This effectively turns assignment into a function call, allowing you to add whatever additional behaviour you like: class Foo(QWidget): valueChanged = pyqtSignal(object)

pyqt: A correct way to connect multiple signals to the same function in pyqt (QSignalMapper not applicable)

雨燕双飞 提交于 2020-07-17 12:41:39
问题 I've ready many posts on how to connect multiple signals to the same event handler in python and pyqt. For example, connecting several buttons or comboboxes to the same function. Many examples show how to do this with QSignalMapper, but it is not applicable when the signal carries a parameter, as with combobox.currentIndexChanged Many people suggest it can be made with lambda. It is a clean and pretty solution, I agree, but nobody mentions that lambda creates a closure, which holds a

pyqt: A correct way to connect multiple signals to the same function in pyqt (QSignalMapper not applicable)

筅森魡賤 提交于 2020-07-17 12:40:25
问题 I've ready many posts on how to connect multiple signals to the same event handler in python and pyqt. For example, connecting several buttons or comboboxes to the same function. Many examples show how to do this with QSignalMapper, but it is not applicable when the signal carries a parameter, as with combobox.currentIndexChanged Many people suggest it can be made with lambda. It is a clean and pretty solution, I agree, but nobody mentions that lambda creates a closure, which holds a

Safe Cross Thread Signals/Slot C++

房东的猫 提交于 2020-05-15 05:08:46
问题 It seem that the only implementation that provide Safe Cross-Thread Signals for both the Signal class and what's being called in the slot is QT. (Maybe I'm wrong?). But I cannot use QT in the project I'm doing. So how could I provide safe Slots call from a different thread (Using Boost::signals2 for example)? Are mutex inside the slot the only way? I think signals2 protect themself but not what's being done inside the slot. Thanks 回答1: You can combine boost::bind and boost ASIO to create

How to tell the mouse button using QApplication::mouseButtons() in a “click” slot?

一个人想着一个人 提交于 2020-03-16 09:02:51
问题 I have a QMainWindow, and want to handle the "clicked" signal from a smaller widget (such as tableview) inside it. Originally I connect the signal to a slot of this QMainWindow, this is the most common approach. Now I need to tell which mouse button is clicked, and do different things for left and right button, I found that the "clicked" signal don't have the mouse event information. I tried to implement the "mousePressEvent" function,but there are still some problem. if the mouse action is

Receiving pyqtSignal from Singleton

ぐ巨炮叔叔 提交于 2020-02-04 01:46:47
问题 There's singleton class in python: from PyQt5.QtCore import QObject, pyqtSignal import logging class Singleton(QObject): _instance = None def __new__(cls, *args, **kwargs): if not isinstance(cls._instance, cls): cls._instance = QObject.__new__(cls, *args, **kwargs) return cls._instance class DataStatus(Singleton, QObject): ''' ''' dataChanged = pyqtSignal(str) __val = 'init' def __init__(self): super().__init__() def setVal(self, val): self.dataChanged.emit('emit: ' + val) logging.debug('emit