signals-slots

Invoke slot asynchronously without connecting to it using clear line of code

人盡茶涼 提交于 2019-12-02 04:41:31
I have encountered quite freaky bug - QAction::trigger caused blocking dialog to appear, which caused my server which called trigger to go stuck (eg. not able to process socket signals until dialog was closed). I figured out a workaround. I connect signal void triggerWorkaround() to slot QAction::trigger using Qt::QueuedConnection and I emit it: QObject::connect(this, &HackClass::triggerWorkaround, targetAction_.data(), &QAction::trigger, Qt::QueuedConnection); emit triggerWorkaround(); QObject::disconnect(this, nullptr, targetAction_.data(), nullptr); But that's three lines of confusing code.

In which thread is a slot executed, and can I redirect it to another thread?

半城伤御伤魂 提交于 2019-12-02 03:42:56
While learning more about the Signal/Slot mechanic in Qt , I was confused in which context a slot is executed, so I wrote the following example to test it: from PyQt5.Qt import * # I know this is bad, but I want a small example import threading def slot_to_output_something ( something ): print( 'slot called by', threading.get_ident(), 'with', something ) class Object_With_A_Signal( QObject ): sig = pyqtSignal( str ) class LoopThread( QThread ): def __init__ ( self, object_with_a_signal ): self.object_with_a_signal = object_with_a_signal super().__init__() def run ( self ): print( 'loop running

Qt Connecting SIGNAL and SLOT in object member of MainWindow

那年仲夏 提交于 2019-12-02 03:42:34
I have a class MyClass with: - private: pushButton *button; void connectSignalAndSlot(); - private slot: void buttonAction(); I want to connect these in MyClass using connectSignalAndSlot(), like so: void MyClass::connectSignalAndSlot() { QObject::connect(button,SIGNAL(clicked()),this,SLOT(buttonAction())); } This gives me an error of no matching function for call to 'QObject::connect(QPushButton*&, const char*, MyClass* const, const char*)'; If I inherit QObject with MyClass, the program compiles and starts, but then I get the following issues displayed in my Application Output pane: QObject:

Qt: Connecting protected QListWidget::itemChanged signal to a slot

不羁的心 提交于 2019-12-02 03:41:24
问题 I used below syntax in Qt5 according to new connect syntax to avoid type mismatches of slot and signals for a a QListWidget with checkable items. connect(item, &QListWidget::itemChanged,this , &mainWindow::checkItemChanged); I want to run my slot in case any of list item changed its state. In order to this this I used itemChanged signal due to this answer, but it is protected and compile time error raise as below: error: ‘void QListWidget::itemChanged(QListWidgetItem*)’ is protected How can I

Qt connection type between threads: why does this work?

柔情痞子 提交于 2019-12-02 00:39:12
问题 While trying to make a multi-camera system work with a different thread handling a different camera, I couldn't get signals and slots working correctly between different threads. I knew something was wrong with the fact that the object sending the signal and the related slot's object were living in different threads, and thus I knew that I probably only had to find an appropriate "connection type" parameter for the connection. Eventually, I ended up discovering that only using Qt:

Qt connection type between threads: why does this work?

徘徊边缘 提交于 2019-12-01 22:34:06
While trying to make a multi-camera system work with a different thread handling a different camera, I couldn't get signals and slots working correctly between different threads. I knew something was wrong with the fact that the object sending the signal and the related slot's object were living in different threads, and thus I knew that I probably only had to find an appropriate "connection type" parameter for the connection. Eventually, I ended up discovering that only using Qt::DirectConnection would make everything work as it should. Find the simplified code below. Here's a small

Given a pyqtBoundSignal how to determine the slot?

天涯浪子 提交于 2019-12-01 20:23:29
问题 Given the signal, how can I determine the slot that a particular signal is connected to? I am familiar with how to connect signal and slots, this is more for debugging purposes. I am using pyqt5, python 2.7 回答1: There is no such thing as "the" slot, because a signal can be connected to multiple slots, or multiple other signals, or the same signal/slot multiple times. But in any case, there is no built-in API that can list all the current connections. You can get a count of the current

How to create pyqtSignals dynamically

帅比萌擦擦* 提交于 2019-12-01 20:15:21
Is there any possibility to create signals at runtime when needed? I'm doing something like this in a function: class WSBaseConnector(QObject) def __init__(self) -> None: super(QObject, self).__init__() self._orderBookListeners: Dict[str, pyqtSignal[OrderBookData]] = {} def registerOrderBookListener(self, market: str, listener: Callable[[OrderBookData], None], loop: AbstractEventLoop) -> None: try: signal = self._orderBookListeners[market] except KeyError: signal = pyqtSignal(OrderBookData) signal.connect(listener) self._orderBookListeners[market] = signal else: signal.connect(listener) As you

Given a pyqtBoundSignal how to determine the slot?

扶醉桌前 提交于 2019-12-01 20:15:07
Given the signal, how can I determine the slot that a particular signal is connected to? I am familiar with how to connect signal and slots, this is more for debugging purposes. I am using pyqt5, python 2.7 There is no such thing as "the" slot, because a signal can be connected to multiple slots, or multiple other signals, or the same signal/slot multiple times. But in any case, there is no built-in API that can list all the current connections. You can get a count of the current connections for a signal, like this: count = button.receivers(button.clicked) There is also connectNotify and

How to connect a QSlider to QDoubleSpinBox

假装没事ソ 提交于 2019-12-01 20:10:45
问题 I want to connect a QSlider to a QDoubleSpinBox but while the code compiles fine and runs for simple QSpinBox, it doesn't work for QDoubleSpinBox QSlider *horizontalSlider1 = new QSlider(); QDoubleSpinBox *spinBox1 = new QDoubleSpinBox(); connect(spinBox1, SIGNAL(valueChanged(double)),horizontalSlider1,SLOT(setValue(double)) ); connect(horizontalSlider1,SIGNAL(valueChanged(double)),spinBox1,SLOT(setValue(double)) ); 回答1: QSlider and QDoubleSpinBox take different types of arguments in