signals-slots

Call function directly vs emiting Signal (Qt - Signals and Slots)

送分小仙女□ 提交于 2019-12-21 05:47:12
问题 At this point I'm in a dilemma to when to emit a signal vs calling a method in another class directly (same thread). For example, in the tutorial I'm doing I'm connecting the NotifyConnected signal of the Instrument class (Model) to the onConnected slot of 'this' aka The View Manager, refer to SetupViewManager::WireButtons(), third line in code. (I'm using MVVM design pattern). Here signals and slots makes sense as the Instruments class (Model) should not know anything about the View Manager.

Qt thread does not stop after calling exit/quit

匆匆过客 提交于 2019-12-21 05:06:05
问题 I'm trying to find a better understanding of Qt signals and slots in conjunction with threads. So I tried this minimal application: foo.h: #include <QObject> class A : public QObject { Q_OBJECT public: void doit(); signals: void x(); }; class B : public QObject { Q_OBJECT public slots: void h(); }; foo.cpp: #include "foo.h" #include <QThread> #include <QCoreApplication> void B::h() { qDebug("[%d] B::h() here!", (int) QThread::currentThreadId()); QCoreApplication::instance()->quit(); } void A:

How to send a Qt signal containing a cv::Mat?

巧了我就是萌 提交于 2019-12-21 04:24:10
问题 In short, I get following error: QObject::connect: Cannot queue arguments of type 'cv::Mat' (Make sure 'cv::Mat' is registered using qRegisterMetaType().) What I'm trying to do is send a signal containing two cv::Mat images from a QThread to the main thread, so that I can display the output. There's no compile time error, but when I run the program, it gets stuck at a breakpoint in qglobal.h ( inline void qt_noop() {} ). I've tried to add Q_DECLARE_METATYPE(cv::Mat) to the code, to no avail.

applying python functions directly to Qt designer as signals

て烟熏妆下的殇ゞ 提交于 2019-12-20 10:24:54
问题 I am new to Qt and GUI programming overall but i have done a fair bit of coding in python - writing modules and so on. I need to develop simple GUIs for some of my old modules. What i am trying to do can be represented by the following simple example: def f(x, y): z = x + y return z For this function i will give two line-edits for x and y and one for z. Now i create a push-button 'calculate' and when i do that i want it to take x and y from the line-edits run the function f(x,y) and give the

Qt Connecting SIGNAL and SLOT in object member of MainWindow

余生长醉 提交于 2019-12-20 04:50:33
问题 I have a class MyClass with: - private: pushButton *button; void connectSignalAndSlot(); - private slot: void buttonAction(); I want to connect these in MyClass using connectSignalAndSlot(), like so: void MyClass::connectSignalAndSlot() { QObject::connect(button,SIGNAL(clicked()),this,SLOT(buttonAction())); } This gives me an error of no matching function for call to 'QObject::connect(QPushButton*&, const char*, MyClass* const, const char*)'; If I inherit QObject with MyClass, the program

In which thread is a slot executed, and can I redirect it to another thread?

故事扮演 提交于 2019-12-20 04:20:00
问题 While learning more about the Signal/Slot mechanic in Qt, I was confused in which context a slot is executed, so I wrote the following example to test it: from PyQt5.Qt import * # I know this is bad, but I want a small example import threading def slot_to_output_something ( something ): print( 'slot called by', threading.get_ident(), 'with', something ) class Object_With_A_Signal( QObject ): sig = pyqtSignal( str ) class LoopThread( QThread ): def __init__ ( self, object_with_a_signal ): self

QT5 Radio button signal not compatible with function, even though it should be

萝らか妹 提交于 2019-12-20 02:58:06
问题 According to the QT5 docs, the QRadioButton inherits the 4 signals from QAbstractButton, which includes the clicked signal. The template for it is clicked(bool checked = false) so I'm confused why this code returns a long error message, part of which is error: static assertion failed: Signal and slot arguments are not compatible . Code (Simplified, may contain mistakes that are not part of the original): #include <QApplication> #include <QMainWindow> #include <QRadioButton> #include <iostream

Is there a tidier way to connect many Qt widgets of different types to the same slot?

假如想象 提交于 2019-12-20 02:15:18
问题 I am trying to make an options dialog that saves as much time as possible when applying the settings. The widgets used are spread across 4 tabs and are a selection of group boxes, check boxes, radio buttons, text entry fields, spin counters and combo-boxes amongst possible others but these are most common. I've got a boolean flag in each tab that I want changed to true if any single widget on it changed in some way. this would mean that when the apply method is invoked the dialog can check

Boost signals2 automatic connection management and changing the mutex type of a signal

人盡茶涼 提交于 2019-12-19 11:36:19
问题 I am trying to use automatic connection management and changing the mutex type of a signal for a template function. The following code compiles and executes fine using gcc-4.3.4. (http://ideone.com/LLN6d) #include <boost/signals2.hpp> #include <boost/enable_shared_from_this.hpp> #include <stdio.h> class Simple : public boost::enable_shared_from_this< Simple > { private: typedef boost::signals2::signal_type<void( int ), boost::signals2::keywords::mutex_type< boost::signals2::dummy_mutex > >:

Qt Signals/Slots and Threads

瘦欲@ 提交于 2019-12-19 07:38:08
问题 I'm new to GUI programming and multithreading. I am in the process of creating a real-time app that receives information from my car and renders it in some meaningful way. My app is layed out as 3 threads, the GUI (main thread), the rendering thread and the hardware comm thread. Inbetwen the the render and the hardware threads is a shared ring buffer. In the render I have created a timer so that it draws the new interface 20 times a second. I would like the thread to notify the main thread