signals-slots

stack object Qt signal and parameter as reference

大憨熊 提交于 2019-11-28 17:53:18
May I have a "dangling reference" with the following code (in an eventual slot connected to the myQtSignal)? class Test : public QObject { Q_OBJECT signals: void myQtSignal(const FooObject& obj); public: void sendSignal(const FooObject& fooStackObject) { emit myQtSignal(fooStackObject); } }; void f() { FooObject fooStackObject; Test t; t.sendSignal(fooStackObject); } int main() { f(); std::cin.ignore(); return 0; } Particularly if emit and slot are not executed in the same thread. HostileFork UPDATE 20-APR-2015 Originally I believed that passing a reference to a stack-allocated object would be

Is the PySide Slot Decorator Necessary?

蹲街弑〆低调 提交于 2019-11-28 17:14:47
I've seen some example code for PySide slots that uses the @QtCore.Slot decorator, and some that does not. Testing it myself, it doesn't seem to make a difference. Is there a reason I should or should not use it? For example, in the following code: import sys from PySide import QtCore # the next line seems to make no difference @QtCore.Slot() def a_slot(s): print s class SomeClass(QtCore.QObject): happened = QtCore.Signal(str) def __init__(self): QtCore.QObject.__init__(self) def do_signal(self): self.happened.emit("Hi.") sc = SomeClass() sc.happened.connect(a_slot) sc.do_signal() the @QtCore

PySide (or PyQt) signals and slots basics

耗尽温柔 提交于 2019-11-28 12:45:13
Consider a simple example like this which links two sliders using signals and slots: from PySide.QtCore import * from PySide.QtGui import * import sys class MyMainWindow(QWidget): def __init__(self): QWidget.__init__(self, None) vbox = QVBoxLayout() sone = QSlider(Qt.Horizontal) vbox.addWidget(sone) stwo = QSlider(Qt.Horizontal) vbox.addWidget(stwo) sone.valueChanged.connect(stwo.setValue) if __name__ == '__main__': app = QApplication(sys.argv) w = MyMainWindow() w.show() sys.exit(app.exec_()) How would you change this so that the second slider moves in the opposite direction as the first?

Qt: SIGNAL, SLOT Macro declaration [duplicate]

痞子三分冷 提交于 2019-11-28 12:43:16
Possible Duplicate: Is it possible to see definition of Q_SIGNALS, Q_SLOT, SLOT(), SIGNAL() macros? (Qt) I couldn't find on Google, the declaration of the macros, SIGNAL and SLOT, in Qt. When we say, connect(button1, SIGNAL (clicked()), this, SLOT (slotButton1())); I would like to understand, which all kinds of parameters does the highlighted macros accept? Any link to doc would be appreciated. EDIT 1 The link I got through Neil's comment below says: #define SLOT(a) "1"#a and what does a represent here? It is not shown in that link. Bart As per the OPs request: As Neil said, the SLOT and

PyQt: How to send a stop signal into a thread where an object is running a conditioned while loop?

 ̄綄美尐妖づ 提交于 2019-11-28 12:36:36
I'm doing some multi-threading. I have a worker class with a work method, which I send into a separate QThread . The work method has a conditioned while loop inside. I want to be able to send a signal to the worker object to stop it (changing the _running condition to false). This will cause the while loop to exit, and a finished signal to be sent from the worker object (which is connected to the quit slot of the worker's thread). The false condition is sent to the worker object via a signal, but it is never received, which I believe is because the while loop blocks the event-loop of its

How to implement a simple button in PyQt

牧云@^-^@ 提交于 2019-11-28 12:07:34
I want to implement a simple button in PyQt which prints "Hello world" when clicked. How can I do that? I am a real newbie in PyQt. If you're new to PyQt4, there are some useful tutorials on the PyQt Wiki to get you started. But in the meantime, here's your "Hello World" example: from PyQt4 import QtGui, QtCore class Window(QtGui.QWidget): def __init__(self): QtGui.QWidget.__init__(self) self.button = QtGui.QPushButton('Test', self) self.button.clicked.connect(self.handleButton) layout = QtGui.QVBoxLayout(self) layout.addWidget(self.button) def handleButton(self): print ('Hello World') if _

Qt: dynamic widgets signal and slot connection

主宰稳场 提交于 2019-11-28 05:36:09
问题 In my Qt app, I create some of my widgets dynamically. Among them are QToolButtons that need to have a similar behavior. Here is how the widgets are created: QMap<QString, QToolButton*> unselectButtonMap; foreach(QString instance, ...) { unselectButtonMap[instance] = new QToolButton; myLayout->addWidget(unselectButtonMap[instance]); QObject::connect(unselectButtonMap[instance],SIGNAL(clicked()),this,SLOT(unselectInstance())); } Now I would like the unselectInstence slot to know which instance

Qt Designer, missing “go to slot” in context menu?

隐身守侯 提交于 2019-11-28 04:39:26
问题 I've been watching a Qt tutorial series on YouTube, in which the author shows how to call a function, when a button is pressed. He right-clicked on the button in Qt Creator IDE and chose "Go to slot", from where he chose the signal which would fire the generated function. Since I am used to develop with Netbeans, I simply tried to follow his example using the embedded Qt Designer. Unfortunately, there is no "Go to slot..." entry when I right-click on my button or any widget. I could, of

Is it possible to see definition of Q_SIGNALS, Q_SLOT, SLOT(), SIGNAL() macros? (Qt)

浪子不回头ぞ 提交于 2019-11-28 04:01:02
问题 Is it possible to see definition of Q_SIGNALS, Q_SLOT, SLOT(), SIGNAL() macros in Qt framework? P.S. Google gave me nothing in this question. 回答1: Form qobjectdefs.h , for a non-debug compilation: #define Q_SLOTS #define Q_SIGNALS protected #define SLOT(a) "1"#a #define SIGNAL(a) "2"#a The Q_SLOTS and Q_SIGNALS declarations are only treated specially by the moc run, in the final compilation they reduce to simple method declarations. SIGNAL() and SLOT() create names from the provided

QT + How to call slot from custom C++ code running in a different thread

帅比萌擦擦* 提交于 2019-11-28 03:07:53
问题 I am new to QT and I am doing some learning. I would like to trigger a slot that modify a GUI widget from a C++ thread(Currently a Qthread). Unfortunatly I get a: ASSERTION failed at: Q_ASSERT(qApp && qApp->thread() == QThread::currentThread()); here is some code: (MAIN + Thread class) class mythread : public QThread { public: mythread(mywindow* win){this->w = win;}; mywindow* w; void run() { w->ui.textEdit->append("Hello"); //<--ASSERT FAIL //I have also try to call a slots within mywindow