signals-slots

Connect QML signal to C++11 lambda slot (Qt 5)

早过忘川 提交于 2019-11-28 02:42:55
问题 Connecting a QML signal to a regular C++ slot is easy: // QML Rectangle { signal foo(); } // C++ old-style QObject::connect(some_qml_container, SIGNAL(foo()), some_qobject, SLOT(fooSlot()); // works! However, no matter what I try, I cannot seem to be able to connect to a C++11 lambda function slot. // C++11 QObject::connect(some_qml_container, SIGNAL(foo()), [=]() { /* response */ }); // fails... QObject::connect(some_qml_container, "foo()", [=]() { /* response */ }); // fails... Both

How to implement itemChecked and itemUnchecked signals for QTreeWidget in PyQt4?

白昼怎懂夜的黑 提交于 2019-11-28 01:34:19
问题 Where are the signals itemChecked and itemUncheсked on the QTreeWidget? Qt Signals: (quote from PyQt4 QTreeWidget documentation page) void currentItemChanged (QTreeWidgetItem *,QTreeWidgetItem *) void itemActivated (QTreeWidgetItem *,int) void itemChanged (QTreeWidgetItem *,int) void itemClicked (QTreeWidgetItem *,int) void itemCollapsed (QTreeWidgetItem *) void itemDoubleClicked (QTreeWidgetItem *,int) void itemEntered (QTreeWidgetItem *,int) void itemExpanded (QTreeWidgetItem *) void

waiting for a signal

荒凉一梦 提交于 2019-11-27 23:43:45
I am working on an application which uploads the content of the file to server. To upload the file to server I am using ‘QNetworkAccessManager’ class. Since it works as asynchronous way, I changed it to work as synchronous way by using QEventLoop. Class FileTransfer { Public : QNetworkAccessManager mNetworkManager; Void Upload(QNetworkRequest request, QIODevice *data) { responce = mNetworkManager.put(request, data); EventLoop.exec(); ReadResponce(responce); } Void Stop() { responce ->close(); } } In my sample application I have 2 windows. 1st to select the files and 2nd to show the progress.

Qt: meaning of slot return value?

自作多情 提交于 2019-11-27 22:44:19
According to the documentation the return value from a slot doesn't mean anything. Yet in the generated moc code I see that if a slot returns a value this value is used for something. Any idea what does it do? Here's an example of what I'm talking about. this is taken from code generated by moc. 'message' is a slot that doesn't return anything and 'selectPart' is declared as returning int. case 7: message((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< int(*)>(_a[2]))); break; case 8: { int _r = selectPart((*reinterpret_cast< AppObject*(*)>(_a[1])),(*reinterpret_cast< int(*)>

Qt Signals and Slots object disconnect?

霸气de小男生 提交于 2019-11-27 21:56:31
I am wondering if i need to disconnect singals and slots if i destroy the signal emitting object. Here is an example: QAudioOutput * audioOutput = new QAudioOutput(format,mainWindow); connect(audioOutput,SIGNAL(stateChanged(QAudio::State)),this,SLOT(stateChanged(QAudio::State))); delete audioOutput; audioOutput = new QAudioOutput(format,mainWindow); connect(audioOutput,SIGNAL(stateChanged(QAudio::State)),this,SLOT(stateChanged(QAudio::State))); Will this automatically disconnect the signal from the old audioOutput, or will it lead to mem leaks or some other undefined behavior ? Thank you in

How signal and slots are implemented under the hood?

我怕爱的太早我们不能终老 提交于 2019-11-27 21:11:43
This question is already asked in this forum but I don't understand the concept. I was reading around and it seems that signal and slots are implemented using function pointers i.e the signal is one big function which inside it calls all connected slots (function pointers). Is this correct? And what is the role of the generated moc files in the whole story? I don't understand how the signal function knows which slots to call i.e which slots are connected to this signal. Thanks for your time P Shved Qt implements these things in a way that resembles interpreted languages. I.e. it constructs

Qt signals and slots: permissions

萝らか妹 提交于 2019-11-27 20:30:29
问题 There are discrepancies between respected answers here on SO and the actual Qt docs. I've read this question and I want some further clarification. Can anyone confirm: A signal is always protected , therefore it can be emitted only by the class or any of its subclasses. I'm not sure this is true; the question above shows answers supporting this statement. But the Qt docs say: Signals are public access functions and can be emitted from anywhere, but we recommend to only emit them from the

Does large use of signals and slots affect application performance?

这一生的挚爱 提交于 2019-11-27 18:45:48
The question is just done for educational purpose: Does the use of 30-50 or more pairs of signals and slots between two object (for example two threads) affect the application performance, runtime or response times? Kuba Ober First of all, you should probably not put any slots in QThreads. QThreads aren't really meant to be derived from other than by reimplementing the run method and private methods (not signals!). A QThread is conceptually a thread controller, not a thread itself. In most cases you should deal with QObjects. Start a thread, then move the object instance to that thread. That's

Qt “private slots:” what is this?

限于喜欢 提交于 2019-11-27 18:39:26
I understand how to use it, but the syntax of it bothers me. What is "private slots:" doing? I have never seen something between the private keyword and the : in a class definition before. Is there some fancy C++ magic going on here? And example here: #include <QObject> class Counter : public QObject { Q_OBJECT public: Counter() { m_value = 0; } int value() const { return m_value; } public slots: void setValue(int value); ... Russell Davis Slots are a Qt-specific extension of C++. It only compiles after sending the code through Qt's preprocessor, the Meta-Object Compiler (moc). See http://doc

Why do I need to decorate connected slots with pyqtSlot?

故事扮演 提交于 2019-11-27 18:03:48
问题 I'm using pyqt5, and I have several methods connected using code similar to the following: self.progress.canceled.connect(self.cancel) Where, for example, self.cancel is: def cancel(self): self.timer.stop() This code seems to work cleanly in multiple scenarios, without ever decorating cancel with pyqtSlot or doing anything special with it. My questions are: What am I losing by doing it this way? What is the reason pyqtSlot is required? 回答1: The main purpose of pyqtSlot is to allow several