signals-slots

Emitting signals from a Python thread using QObject

故事扮演 提交于 2019-12-01 04:05:25
问题 I would like to know what are the consequences of emitting a signal from a regular python thread within a QObject, compared with a QThread. See the following class: class MyObject(QtCore.QObject): def __init__(self): super().__init__() sig = pyqtSignal() def start(self): self._thread = Thread(target=self.run) self._thread.start() def run(self): self.sig.emit() # Do something Now, assuming that in the GUI thread, I have: def __init__(self): self.obj = MyObject() self.obj.sig.connect(self.slot)

Qt - no such signal error

回眸只為那壹抹淺笑 提交于 2019-12-01 03:52:09
I'm trying to trigger a signal when a double click happens in one of the draggable widgets on the fridge magnets example . Here's the changes I made to the example source: DragLabel: class DragLabel : public QLabel { public: DragLabel(const QString &text, QWidget *parent); QString labelText() const; public slots: void testSlot(){qDebug()<<"testSlot";} //<-- implemented this slot protected: void mouseDoubleClickEvent(QMouseEvent *ev){emit testSignal();} //<-- overriden this method private: QString m_labelText; signals: void testSignal(); //<-- added this signal }; The only thing I changed in

Qt: How to implement common base-class signal/slot functionality for all widgets and widget types (via a virtual base class slot)?

谁说我不能喝 提交于 2019-11-30 15:48:58
问题 I would like to derive all of my widgets from a base class widget that automatically establishes a signal/slot connection between a slot for the class and a (rarely called) signal. The slot is a virtual function, so that any widgets for which I wish to implement custom functionality can derive from the virtual slot function. In the desired scenario, all my widgets would derive from this base class with the virtual slot, so that by default all of my widget instances would be connected to the

Qt: How to implement common base-class signal/slot functionality for all widgets and widget types (via a virtual base class slot)?

故事扮演 提交于 2019-11-30 15:38:18
I would like to derive all of my widgets from a base class widget that automatically establishes a signal/slot connection between a slot for the class and a (rarely called) signal. The slot is a virtual function, so that any widgets for which I wish to implement custom functionality can derive from the virtual slot function. In the desired scenario, all my widgets would derive from this base class with the virtual slot, so that by default all of my widget instances would be connected to the desired signal with a slot defined for the object (with default behavior from the base class). I know

How to keep the source signal's parameters while using QSignalMapper?

拥有回忆 提交于 2019-11-30 14:01:48
I ran into a problem that I need to keep the mapped source signal's parameters. So far I only found examples to map signals without any parameter. For example, the clicked() signal: signalMapper = new QSignalMapper(this); signalMapper->setMapping(taxFileButton, QString("taxfile.txt")); connect(taxFileButton, SIGNAL(clicked()), signalMapper, SLOT (map())); connect(signalMapper, SIGNAL(mapped(QString)), this, SLOT(readFile(QString))); However, I would need to map some signal with its own parameters, for example the clicked(bool) signal, then the SLOT need to have two arguments doStuff(bool

Qt signals and slots, threads, app.exec(), and related queries

吃可爱长大的小学妹 提交于 2019-11-30 09:34:08
[related to this question ] I wrote this piece of code to understand how qt signals and slots work. I need someone to explain the behaviour, and to tell me if I'm right about my own conclusions. My program: connectionhandler.h #ifndef CONNECTIONHANDLER_H #define CONNECTIONHANDLER_H #include <QTcpServer> class ConnectionHandler : public QObject { Q_OBJECT public: ConnectionHandler(); public slots: void newConn(); private: QTcpServer *server; }; #endif // CONNECTIONHANDLER_H connectionhandler.cpp #include "connectionhandler.h" #include <QTextStream> ConnectionHandler::ConnectionHandler() {

Is it possible to emit a Qt signal from a const method?

你离开我真会死。 提交于 2019-11-30 08:07:44
In particular, I am implementing a QWizardPage ("MyWizardPage") for a QWizard, and I want to emit a signal ("sigLog") from my override of the QWizardPage::nextId virtual method. Like so: class MyWizardPage : public QWizardPage { Q_OBJECT public: MyWizardPage(); virtual int nextId() const; Q_SIGNALS: void sigLog(QString text); }; int MyWizardPage::nextId() const { Q_EMIT sigLog("Something interesting happened"); } But when I try this, I get the following compile error on the Q_EMIT line: Error 1 error C2662: 'MyWizardPage::sigLog' : cannot convert 'this' pointer from 'const MyWizardPage' to

How does Qt implement signals and slots?

大兔子大兔子 提交于 2019-11-30 06:56:42
问题 Can someone explain to me the basic idea of Qt signals&slots mechanism IMPLEMENTATION? I want to know what all those Q_OBJECT macros do "in plain C++". This question is NOT about signals&slots usage. added: I know that Qt uses moc compiler to transform Qt-C++ in plain C++. But what does moc do? I tried to read "moc_filename.cpp" files but I have no idea what can something like this mean void *Widget::qt_metacast(const char *_clname) { if (!_clname) return 0; if (!strcmp(_clname, qt_meta

Is it valid to define a pure virtual signal in C++/Qt?

别来无恙 提交于 2019-11-30 06:38:03
问题 I am making an abstract-base-class and was thinking I might want a pure virtual signal. But when I compiled I get a warning for the pure virtual signals I have defined: ../FILE1.h:27: Warning: Signals cannot be declared virtual ../FILE1.h:28: Warning: Signals cannot be declared virtual Is it valid to define a pure virtual signal in C++/Qt? Is it valid to define a virtual signal? Qt's signal and slot documentation page says you can define virtual slots but doesn't talk about signals. I can't

PyQt4 @pyqtSlot: what is the result kwarg for?

我们两清 提交于 2019-11-30 04:55:39
问题 By reading this, two questions came up: 1. It says it is sometimes necessary to explicitly mark a Python method as being a Qt slot While I always use the @pyqtSlot decorator because it says: Connecting a signal to a decorated Python method also has the advantage of reducing the amount of memory used and is slightly faster I ask myself: in which specific cases is it necessary? and: Are there any advantages of not using the @pyqtSlot decorator? 2. The result keyword argument, what is its