signals-slots

QObject based class has a queued connection to itself

北城以北 提交于 2019-12-01 18:40:21
问题 I was digging into some source code I am working on. I found a peculiar statement that someone had coded. The source code is a GUI application with a QML GUI and uses QT 4.7.x. The snippet below belongs to core application logic. // connect signal-slots for decoupling QObject::connect (this, SIGNAL(setCurrentTaskSignal(int)), this, SLOT(SetCurrentTaskSlot(int)), Qt::QueuedConnection); It's strange that the object connects to itself via a queued connection which essentially means that the

QObject based class has a queued connection to itself

纵然是瞬间 提交于 2019-12-01 18:19:41
I was digging into some source code I am working on. I found a peculiar statement that someone had coded. The source code is a GUI application with a QML GUI and uses QT 4.7.x. The snippet below belongs to core application logic. // connect signal-slots for decoupling QObject::connect (this, SIGNAL(setCurrentTaskSignal(int)), this, SLOT(SetCurrentTaskSlot(int)), Qt::QueuedConnection); It's strange that the object connects to itself via a queued connection which essentially means that the object may "live" in different threads at the same time? At first glance It didn't made any sense to me.

Cannot connect (null)::selectionChanged to QTableView

我怕爱的太早我们不能终老 提交于 2019-12-01 17:57:10
问题 I have the following promoted QTableView: class QRightClickableTableView : public QTableView { Q_OBJECT public: explicit QRightClickableTableView(QWidget *parent = 0): QTableView(parent) {} private slots: void mouseReleaseEvent(QMouseEvent *e) { if(e->button()==Qt::RightButton) emit rightClicked(); else if (e->button()==Qt::LeftButton) emit leftClicked(); } signals: void rightClicked(); void leftClicked(); }; When binding the selectionChanged signal of QRightClickableTableView, but getting an

Using any c++ function as a Qt slot

风流意气都作罢 提交于 2019-12-01 15:17:06
Is there a way to use any C++ function as a Qt slot, without having its class inheriting from QWidget? pnezis You cannot in Qt versions < Qt 5. In order to use signals/slots the meta object compiler has to be invoked. To make this happen your class should meet the following requirements: Inherit from QObject or any other subclass (eg QWidget , QPushButton etc) The Q_OBJECT macro should be defined in the private section of the class in order to enable meta-object features such as slots Use the Qt keywords slots and signals in order to declare which functions should be handles by the meta

Using any c++ function as a Qt slot

泄露秘密 提交于 2019-12-01 15:03:47
问题 Is there a way to use any C++ function as a Qt slot, without having its class inheriting from QWidget? 回答1: You cannot in Qt versions < Qt 5. In order to use signals/slots the meta object compiler has to be invoked. To make this happen your class should meet the following requirements: Inherit from QObject or any other subclass (eg QWidget , QPushButton etc) The Q_OBJECT macro should be defined in the private section of the class in order to enable meta-object features such as slots Use the

Qt signal slot cv::Mat unable to read memory access violation

浪子不回头ぞ 提交于 2019-12-01 14:31:58
I have a Microsoft visual studio application that is grabbing frames from cameras and I am trying to display those frames in a Qt application. I am doing some processing with the frames using OpenCV, so the frames are Mat objects. I use QThreads to parallelize the application. I am getting a Access Violation reading location when I try to emit a Mat signal from my CameraThread class. main.cpp int main(int argc, char *argv[]) { QApplication app(argc, argv); MainWindow window; window.show(); return app.exec(); } mainwindow.cpp #include "main_window.h" MainWindow::MainWindow() { // create a

PyQt and QSignalMapper/lambdas - multiple signals, single slot

浪尽此生 提交于 2019-12-01 14:11:48
I have a list of actions on a menu in PyQt, one for each different feed I want to display. So I have a Y that sets the active feed to Y, Z sets it to Z, etc. (For a webcomic reading program). I have each on the menu, and felt that an automated approach might be better; rather than typing out each time. Something like a function that adds it to a dictionary, then connects it up with a signal for each to a single slot. However, I want that slot function, say it's called Foo, to take a parameter to decide what has been clicked. So if X was clicked, then X, Y passes Y, etc. Looked around, and one

Connecting multiples signal/slot in a for loop in pyqt

前提是你 提交于 2019-12-01 13:21:59
I'm connecting multiple signal/slots using a for loop in PyQt. The code is bellow: # Connect Scan Callbacks for button in ['phase', 'etalon', 'mirror', 'gain']: getattr(self.ui, '{}_scan_button' .format(button)).clicked.connect( lambda: self.scan_callback(button)) What I expect: Connect button phase_scan_button clicked signal to the scan_callback slot and send the string phase as a parameter to the slot . The same for etalon , mirror and gain . What I'm getting: For some reason my functions is always passing the string gain as parameter for all the buttons. Not sure if I'm being stupid (likely

Qt signal slot cv::Mat unable to read memory access violation

不想你离开。 提交于 2019-12-01 12:40:14
问题 I have a Microsoft visual studio application that is grabbing frames from cameras and I am trying to display those frames in a Qt application. I am doing some processing with the frames using OpenCV, so the frames are Mat objects. I use QThreads to parallelize the application. I am getting a Access Violation reading location when I try to emit a Mat signal from my CameraThread class. main.cpp int main(int argc, char *argv[]) { QApplication app(argc, argv); MainWindow window; window.show();

How to use multicore python with PyQt4 process?

爱⌒轻易说出口 提交于 2019-12-01 12:03:23
I am writing an app in pyqt4 that has to read in and parse a lot of xml files. Done single-threaded it takes a while to do all that parsing and make the thousands of python objects corresponding to that incoming xml. I have profiled the code and as far as I can tell it's compute, not I/O, bound. I would like to convert the app to a multi-core model to spread the load around, using a worker-farm model (?Process.Pool in python). However, I would also like to be able to Signal progress from the workers to update the gui. It seems to me from what I have read so far that QThread is not multicore