signals-slots

pyqt4 emiting signals in threads to slots in main thread

Deadly 提交于 2019-11-27 03:48:18
问题 I have some custom signals in my main thread that I would like to emit in my other threads but I'm not sure how to connect them. Could someone post an example? ex: import sys, time from PyQt4 import QtGui as qt from PyQt4 import QtCore as qtcore app = qt.QApplication(sys.argv) class widget(qt.QWidget): signal = qtcore.pyqtSignal(str) def __init__(self, parent=None): qt.QWidget.__init__(self) self.signal.connect(self.testfunc) def appinit(self): thread = worker() thread.start() def testfunc

Is it possible to connect a signal to a static slot without a receiver instance?

大城市里の小女人 提交于 2019-11-27 01:57:26
Is it possible to connect a signal to static slot without receiver instance? Like this: connect(&object, SIGNAL(some()), STATIC_SLOT(staticFooMember())); There is a QApplication::closeAllWindows() function with [static slot] attribute in Qt documentation. And there is an example of using it from the documentation: exitAct = new QAction(tr("E&xit"), this); exitAct->setShortcuts(QKeySequence::Quit); exitAct->setStatusTip(tr("Exit the application")); connect(exitAct, SIGNAL(triggered()), qApp, SLOT(closeAllWindows())); Is it allowed to do the same action but without passing an instance variable

Connecting slots and signals in PyQt4 in a loop

坚强是说给别人听的谎言 提交于 2019-11-27 01:53:31
Im trying to build a calculator with PyQt4 and connecting the 'clicked()' signals from the buttons doesn't work as expected. Im creating my buttons for the numbers inside a for loop where i try to connect them afterwards. def __init__(self): for i in range(0,10): self._numberButtons += [QPushButton(str(i), self)] self.connect(self._numberButtons[i], SIGNAL('clicked()'), lambda : self._number(i)) def _number(self, x): print(x) When I click on the buttons all of them print out '9'. Why is that so and how can i fix this? This is just, how scoping, name lookup and closures are defined in Python.

QMetaObject::connectSlotsByName: No matching signal

独自空忆成欢 提交于 2019-11-26 22:25:16
问题 I set a QT menu, which is automatically connected with action function on_actionOpen_triggered() . Later I want to pass a filename string to this function in order to call this function manually in a special condition. So I changed the function signature to on_actionOpen_triggered( const char *filename_in ) . After this change the program is running well, but there is a complain in terminal, QMetaObject::connectSlotsByName: No matching signal for on_actionOpen_triggered(const char*) I am

waiting for a signal

喜夏-厌秋 提交于 2019-11-26 21:34:34
问题 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();

Qt: meaning of slot return value?

▼魔方 西西 提交于 2019-11-26 21:07:57
问题 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])));

Qt Signals and Slots object disconnect?

北城以北 提交于 2019-11-26 20:49:45
问题 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

Qt “private slots:” what is this?

萝らか妹 提交于 2019-11-26 19:32:53
问题 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); ... 回答1: Slots are a Qt-specific extension of C++. It only compiles

How to emit cross-thread signal in Qt?

感情迁移 提交于 2019-11-26 18:30:26
Qt documentation states that signals and slots can be direct , queued and auto . It also stated that if object that owns slot 'lives' in a thread different from object that owns signal, emitting such signal will be like posting message - signal emit will return instantly and slot method will be called in target thread's event loop. Unfortunately, documentation do not specify that 'lives' stands for and no examples is available. I have tried the following code: main.h: class CThread1 : public QThread { Q_OBJECT public: void run( void ) { msleep( 200 ); std::cout << "thread 1 started" << std:

Qt: Signals and slots Error: undefined reference to `vtable for

牧云@^-^@ 提交于 2019-11-26 18:28:48
问题 Following example from this link: http://developer.kde.org/documentation/books/kde-2.0-development/ch03lev1sec3.html #include <QObject> #include <QPushButton> #include <iostream> using namespace std; class MyWindow : public QWidget { Q_OBJECT // Enable slots and signals public: MyWindow(); private slots: void slotButton1(); void slotButton2(); void slotButtons(); private: QPushButton *button1; QPushButton *button2; }; MyWindow :: MyWindow() : QWidget() { // Create button1 and connect button1-