signals-slots

Signals vs Signals2

ぐ巨炮叔叔 提交于 2019-12-06 18:52:38
问题 I have application that may benefit from using one of boost's signals libraries over a homegrown solution. The application is multithreaded but the part that does the signal processing is single threaded. Is there any reason to prefer Boost.Signals2 over Boost.Signal if multithreading is not an issue? 回答1: Boost.Signals is now deprecated, and Boost.Signals2 should be used instead (see v1.54 docs) 回答2: Originally, if all the signals and slots were in the same thread, boost.signals was just

Qt: Do events get processed in order?

安稳与你 提交于 2019-12-06 17:02:30
问题 If I had a class A, where one of its functions does: void A::func() { emit first_signal(); emit second_signal(); } Assuming that a class B has 2 slots, one connected to first_signal , and the other to second_signal , is it guaranteed that the slot that is connected to first_signal will always be processed before the second_signal slot? 回答1: If you use direct connection type between signals and slots (Qt::DirectConnection) then the answer is yes. From Qt help system: When a signal is emitted,

PySide emit signal causes python to crash

送分小仙女□ 提交于 2019-12-06 16:24:00
I am working through the book "Rapid Gui Programming with Python and Qt" and am having a problem on the signals/slots project. I have downloaded the authors code to compare against my own, and it all looks the same, however, when I emit a signal from a derived spin box class, python just crashes. Here is the entire code that I have: import sys from PySide.QtCore import * from PySide.QtGui import * class ZeroSpinBox(QSpinBox): zeros = 0 def __init__(self, parent=None): super(ZeroSpinBox, self).__init__(parent) self.connect(self, SIGNAL("valueChanged(int)"), self.checkzero) def checkzero(self):

Connecting multiple signals to a single slot in Qt

♀尐吖头ヾ 提交于 2019-12-06 10:11:53
问题 I'm trying to keep track of the textChanged() signal on for handful of QTextEdits. I want to do the same thing regardless of the text edit emitting the signal: uncheck its associated checkbox in a QListWidget if it becomes empty and leave it checked otherwise. The function I have so for is as follows: void MainWindow::changed() { QString tempStr = ui->hNMRedit->toPlainText(); if(tempStr != "") { ui->checkList->item(0)->setCheckState(Qt::Checked); } else { ui->checkList->item(0)->setCheckState

Updating pointer using signals and slots

女生的网名这么多〃 提交于 2019-12-06 08:46:15
I am very new to Qt; please help me to solve the problem. I am using a thread to perform intensive operations in the background. Meanwhile I want to update the UI, so I am using SIGNALS and SLOTS. To update UI I emit a signal and update UI. Let us consider below sample code, struct sample { QString name; QString address; }; void Update(sample *); void sampleFunction() { sample a; a.name = "Sachin Tendulkar"; a.address = "India" emit Update(&a); } In the above code we are creating a local object and passing the address of a local object. In the Qt document, it says that when we emit a signal it

How do I emit a PySide signal with a custom python type argument?

一世执手 提交于 2019-12-06 05:31:31
问题 I am having trouble correctly using signals in my PySide python Qt program. I want to emit a signal that takes a single argument of a custom python type. The documentation says Signals can be defined using the QtCore.signal() class. Python types and C types can be passed as parameters to it. So I tried the following: from PySide import QtCore from PySide.QtCore import QObject class Foo: pass class Bar(QObject): sig = QtCore.Signal(Foo) def baz(self): foo = Foo() self.sig.emit(foo) bar = Bar()

Correct way to convert old SIGNAL and SLOT to new style?

为君一笑 提交于 2019-12-06 03:29:29
I'm currently trying to convert an old python program from Python 2 to Python 3, and update from PyQt4 to PyQt5. The application uses the old style signal and slots that are not supported under PyQt5. I have figured out most of what needs to be done, but below are a few lines that I can't seem to get working: self.emit(SIGNAL('currentChanged'), row, col) self.emit(SIGNAL("activated(const QString &)"), self.currentText()) self.connect(self,SIGNAL("currentChanged(const QString&)"), self.currentChanged) The top two lines, I have no idea where to start since they don't seem to be attached to

pyqt: How to dynamically update widget property on outer variable value change?

℡╲_俬逩灬. 提交于 2019-12-05 23:55:14
I have class Ui_MainWindow(object) that creates a window with a progress bar and class OtherClass(object) that contains method in which the local int variable increments in cycle. How to connect local variable value change to progres bar value change? mainGUI.py import sys from PyQt4.uic.Compiler.qtproxies import QtGui from PyQt4 import QtGui from Ui_MainWindow import Ui_MainWindow def main(): app = QtGui.QApplication(sys.argv) MainWindow = QtGui.QMainWindow() ui = Ui_MainWindow() ui.setupUi(MainWindow) MainWindow.show() sys.exit(app.exec_()) if __name__ == '__main__': main() Ui_MainWindow.py

Passing QVector<float> from worker thread to main thread via signal/slot

∥☆過路亽.° 提交于 2019-12-05 17:40:45
Currently I have some troubles passing a QVector between to threads. At the moment I have a main thread (GUI-Thread) and an worker thread that emits frequently QVector arrays. Directly before emitting the data inside the vector looks good. The receiver is a slot in the main thread but the Data received in by the slot is garbled. Here are some parts of my code: Emit in the worker thread: void Pipeline::process { QVector<float> buffer(w * h * d); // filling the vector with RGB-Values emit this->pushBuffer(buffer, w, h, d); } Connection of signal and slot in the main thread: QObject::connect(this

How to create new instance of a Q_GADGET struct in QML?

北战南征 提交于 2019-12-05 16:04:06
I can emit signals with structs tagged with Q_GADGET from C++ to QML. Is it possible send such a struct from QML to a C++ slot? My code fails on the first step: creating an instance in QML. This code fails on the first line ... var bs = new BatteryState() bs.percentRemaining = 1.0 bs.chargeDate = new Date() DataProvider.setBatteryState(bs) ... with error: qrc:///main.qml:34: ReferenceError: BatteryState is not defined I can emit a BatteryStatus struct from C++ to QML, but I would like to send one back as a single parameter to a slot. Here is BatteryState.h & BatteryState.cpp: // BatteryState.h