signals-slots

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

别来无恙 提交于 2019-11-29 11:11:27
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. 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 signatures. With visual studio - right click the identifier you're interested in and choose "Go To Definition" or

Emitting signals from a Python thread using QObject

狂风中的少年 提交于 2019-11-29 10:58:15
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) self.obj.start() def slot(self): # Do something the slot is indeed executed when the signal is emitted

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

落爺英雄遲暮 提交于 2019-11-29 10:44:42
问题 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

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

江枫思渺然 提交于 2019-11-29 09:21:54
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 which also fail. }; }; int main(int argc, char *argv[]) { QApplication* a = new QApplication(argc, argv)

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

十年热恋 提交于 2019-11-29 09:16:22
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 attempts fail with a function signature error (no QObject::connect overload can accept these parameters).

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

醉酒当歌 提交于 2019-11-29 07:35:25
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 itemPressed (QTreeWidgetItem *,int) void itemSelectionChanged () At current moment I solved it like this:

How to communicate or switch between two windows in PyQt?

放肆的年华 提交于 2019-11-29 05:19:14
I am developing an application using python and Qt. I have designed 2 Main windows ie..QMainWindow (Not QWidget or QDialog) using Qt. Let it be. 1.LoginWindow -- LoginUI(Qt) 2.StuffWindow --- StuffUI First i should display Login Window. Then i should pass the username to StaffWindow (username needed for managing stuffs) StaffWindow should be shown and LoginWindow Should be Closed.. How can i achieve this..? Help me.. Regardless of your description, I think your LoginWindow should be a QDialog, and your StuffWIndow be the MainWindow, and function like this... Your StuffWindow MainWindow should

Why do I need to decorate connected slots with pyqtSlot?

喜你入骨 提交于 2019-11-29 04:21:12
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? ekhumoro The main purpose of pyqtSlot is to allow several different overloads of a slot to be defined, each with a different signature. It may also be needed

Sending signal from static class method in Qt

元气小坏坏 提交于 2019-11-29 02:50:13
问题 I am trying to code a static callback function that is called frequently from another static function within the same class. My callback function needs to emit a signal but for some reason it simply fails to do so. I have put it under a debugger and the slot never gets called. However when I place the code I used to emit the data in a non-static function it works. Is there a reason I cannot emit a signal from a static function? I have tried declaring a new instance of the class and calling

PyQt Widget connect() and disconnect()

陌路散爱 提交于 2019-11-28 23:27:14
问题 Depending on a conditions I would like to connect/re-connect a button to a different function. Let's say I have a button: myButton = QtGui.QPushButton() For this example let's say I check if there is an internet connection. if connected == True: myButton.clicked.connect(function_A) elif connected == False: myButton.clicked.connect(function_B) First of all I would like to disconnect a button from any function it was already connected before the button is being re-assigned/re-connected to