qt-signals

How to Compress Slot Calls When Using Queued Connection in Qt?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-17 10:42:47
问题 After reading some articles like this about Qt Signal-Slot communications I still have a question concerning the queued connection. If I have some threads sending signals all the time to each other and lets say one thread_slow is running a slow method in it's event loop and another thread_fast is running a fast one that sends multiple signals while the other thread is still running it's slow method.....when the slow method from thread_slow returns to the event loop, will it process all the

Qt signals (QueuedConnection and DirectConnection)

我的梦境 提交于 2019-12-17 04:55:16
问题 I'm having trouble with Qt signals. I don't understand how DirectConnection and QueuedConnection works? I'd be thankful if someone will explain when to use which of these (sample code would be appreciated). 回答1: You won't see much of a difference unless you're working with objects having different thread affinities. Let's say you have QObjects A and B and they're both attached to different threads. A has a signal called somethingChanged() and B has a slot called handleChange() . If you use a

Make window's text unique for each different button

亡梦爱人 提交于 2019-12-13 03:53:04
问题 How can i make one form unique for different buttons? For example: QVector<QString> text { "Iter FIRST", "Iter SECOND" }; for(size_t i = 0; i < 2; ++i) { Form2 * form2 = new Form2(); //creating form connect(this, &MainWindow::SendCurretIteration, fitr, &CurrentIterationForm::ShowCurrentIteration);//connect to the second form` emit MainWindow::SendCurretIteration(text[i]); QPushButton *btnShowForm = new QPushButton(this); btnShowForm->setGeometry(i + 40, i + 100, 50, 50); connect(btnShowForm,

PySide Signal “duplicating” behavior

不羁的心 提交于 2019-12-13 02:56:08
问题 from PySide.QtCore import * class Eggs(QObject): evt_spam = Signal() print "Loaded" a = Eggs() b = Eggs() print a.evt_spam print b.evt_spam print a.evt_spam is b.evt_spam outputs: Loaded <PySide.QtCore.Signal object at 0xa2ff1a0> <PySide.QtCore.Signal object at 0xa2ff1b0> False "Loaded" only printing once (as expected; it is a class variable), but why are 2 instances of the signal being created (if it is also a class variable)? 回答1: It's not being printed when you create a class instance, but

When subclassing QTcpServer, how can I delay emitting the newConnection() signal?

雨燕双飞 提交于 2019-12-13 01:09:04
问题 I want to create an SSL server, so I subclass QTcpServer and I override incomingConnection() , where I create a QSslSocket , set its descriptor, and call QSslSocket::startServerEncryption . At this point I need to wait for QSslSocket::encrypted() signal to be emitted, and only after that should my server emit the newConnection() signal. The client code would then think it's using a QTcpSocket, but will in fact be using a secure socket. But QTcpServer always emits newConnection() after calling

Qt custom QPushButton clicked signal

让人想犯罪 __ 提交于 2019-12-13 00:53:56
问题 I want to send two integers, string and fret, to a SLOT that will process the location of the button that was pressed. The SIGNAL and SLOT argument have to match so I am thinking I need to reimplement the QPushButton::clicked event method. Problem is I am new to Qt and could use some direction. connect(&fretBoardButton[string][fret], SIGNAL(clicked()), this, SLOT (testSlot())); 回答1: If you use the C++11 connection syntax you can use a lambda with calls testSlot with your string and fret

How to detect Windows shutdown or logoff in Qt

人盡茶涼 提交于 2019-12-12 08:49:39
问题 I am porting a Linux app to Windows written in Qt. The application needs to save some settings before closing. On Linux, we can do that by signal handlers for SIGTERM etc. How can I implement the same on Windows. 回答1: If you are using the Qt event loop, you can catch the following signal: void QCoreApplication::aboutToQuit() [signal] This signal is emitted when the application is about to quit the main event loop, e.g. when the event loop level drops to zero. This may happen either after a

PyQt5 one signal and multiple slots

非 Y 不嫁゛ 提交于 2019-12-12 03:34:45
问题 I have come up with a simple signal/slot mechanism below. The signal is called by QSlider when the value is changed via QSlider::valueChanged(). And the slot is called via the QLCDNumber::display() method. What is confusing to me is why PyQt5 has so little documentation and most documentation leads to links for Qt5. The specific issue I have with the code is: 1) If QSlider::valueChanged() (signal) expects an integer as a parameter why do we only pass in QLCDNumber::display() (slot) which is a

QThread Slots behavior

↘锁芯ラ 提交于 2019-12-11 18:06:54
问题 I am new to C++ and Qt and I am wondering what happens if I emit a signal in object1 running in thread1 , to another object2 running in another thread2 and object2 is running an infinite loop for processing? Will the slot in object2 never be called since the thread2 is busy running the loop? 回答1: I am new to C++ and Qt and I am wondering what happens if I emit a signal in object1 running in thread1, to another object2 running in another thread2 and object2 is running an infinite loop for

Automatically create QStackedWidget pages based on Tuple

独自空忆成欢 提交于 2019-12-11 16:28:45
问题 I'm fairly new to python, and I feel this is an advanced question, with that in mind it might be out of the scope of Stack Exchange. Please bear with me. I have a QTreeWidget and QStackedWidget. I have populated the QTreeWidget using a tuple TreeList = ({ 'Header1': (( 'Item11', 'Item12', )), 'Header2': (( 'Item21', 'Item22' )) }) for key, value in TreeList.items(): root = QTreeWidgetItem(self.QTreeWidget, [key]) for val in value: root.addChild(QTreeWidgetItem([val])) I would like to use this