signals-slots

Swing - replacement for Qt signal/slots

时光总嘲笑我的痴心妄想 提交于 2019-12-04 22:51:09
问题 In Qt GUIs it is very convenient use signals & slots - it decouple events passing. When I create some widget that throw signal, I don't have to know in advance who can get it, and later with connect I specify connections. What is parallel in Java/Swing? Can you point to good resources on this issue? 回答1: If none of the existing EventListener implementations meet your requirements, you can create your own custom event. Every JComponent contains a field of type EventListenerList. You can use

Can signal handlers memory leak in PyQt? [duplicate]

最后都变了- 提交于 2019-12-04 21:56:19
问题 This question already has an answer here : Lifetime of object in lambda connected to pyqtSignal (1 answer) Closed 10 days ago . Short question: Can signal handlers memory leak. Long question: In C#, if I attach a handler to an event left_object.left_event += right_object.right_handler Then I need to remove the handler when I get rid of right_object or the garbage collector will never dispose of it (since left_object.left_event retains a pointer to right_object ) Is the same also true of PyQt

Is there a way to stop a boost::signal from calling its slots if one of them returns true?

旧街凉风 提交于 2019-12-04 18:06:32
I am using the boost library and my question is about boost::signals. I have a signal that might call many different slots but only one slot will match the call so I want this particular slot to return true and that the calling will stop. Is it possible? Is it efficient? Can you guys suggest me a better way to do it if it's not efficient? After some research I've found that in boost documentation they write about Slots that return values . They suggest to use a different combiner like this: struct breakIfTrue { template<typename InputIterator> bool operator()(InputIterator first, InputIterator

Connecting multiple signals to a single slot in Qt

♀尐吖头ヾ 提交于 2019-12-04 15:38:11
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(Qt::Unchecked); } } With the current approach, I would have to make a function like this for every

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

Deadly 提交于 2019-12-04 10:33:21
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() bar.baz() But get the following error: Traceback (most recent call last): File "test.py", line 15, in

PyQt_PyObject equivalent when using new-style signals/slots?

一世执手 提交于 2019-12-04 04:56:21
So I have a need to pass around a numpy array in my PyQt Application. I first tried using the new-style signals/slots, defining my signal with: newChunkToProcess = pyqtSignal(np.array()) , however this gives the error: TypeError: Required argument 'object' (pos 1) not found I have worked out how to do this with the old-style signals and slots using self.emit(SIGNAL("newChunkToProcess(PyQt_PyObject)"), np.array([5,1,2])) - (yes, that's just testing data :), but I was wondering, is it possible to do this using the new-style system? The type you're looking for is np.ndarray You can tell this from

QTimer::singleShot() looks for the specified slot in the given object's parent class, not the object itself

强颜欢笑 提交于 2019-12-04 03:57:43
I am fairly new to Qt. I have done some simple modifications to an existing Qt application, but I haven't created any from scratch yet. I also don't have really much experience with certain aspects of C++ in general (class inheritance etc). I have created a new Code::Blocks Qt4-based project and modified the template a bit. I have added two files. Right now the project contains three files: main.cpp, app.h and app.cpp. This is the content of main.cpp : #include <QTimer> #include "app.h" int main(int argc, char* argv[]) { TestApp app(argc, argv); QTimer::singleShot(1000, &app, SLOT(timeout()));

Connecting multiples signal/slot in a for loop in pyqt

本小妞迷上赌 提交于 2019-12-04 02:01:51
问题 I'm connecting multiple signal/slots using a for loop in PyQt. The code is bellow: # Connect Scan Callbacks for button in ['phase', 'etalon', 'mirror', 'gain']: getattr(self.ui, '{}_scan_button' .format(button)).clicked.connect( lambda: self.scan_callback(button)) What I expect: Connect button phase_scan_button clicked signal to the scan_callback slot and send the string phase as a parameter to the slot . The same for etalon , mirror and gain . What I'm getting: For some reason my functions

How to pass variables to slot methods in QT?

时光怂恿深爱的人放手 提交于 2019-12-04 01:17:57
I'm making a little chat messenger program, which needs a list of chat channels the user has joined. To represent this list graphically, I have made a list of QPushButtons , which all represent a different channel. These buttons are made with the following method, and that's where my problem kicks in: void Messenger::addToActivePanels(std::string& channel) { activePanelsContents = this->findChild<QWidget *>(QString("activePanelsContents")); pushButton = new QPushButton(activePanelsContents); pushButton->setObjectName("pushButton"); pushButton->setGeometry(QRect(0, 0, 60, 60)); pushButton-

Call function directly vs emiting Signal (Qt - Signals and Slots)

久未见 提交于 2019-12-03 20:36:17
At this point I'm in a dilemma to when to emit a signal vs calling a method in another class directly (same thread). For example, in the tutorial I'm doing I'm connecting the NotifyConnected signal of the Instrument class (Model) to the onConnected slot of 'this' aka The View Manager, refer to SetupViewManager::WireButtons(), third line in code. (I'm using MVVM design pattern). Here signals and slots makes sense as the Instruments class (Model) should not know anything about the View Manager. (i.e. Passing a reference of the view manager to the model is a no no as it would break the MVVM