signals-slots

Qt Mainwindow menu signals

孤街浪徒 提交于 2019-12-24 11:05:26
问题 I've "Core" object that handles QMainWindow. Core.h code class Core : public QObject { Q_OBJECT public: explicit Core(QObject *parent = 0); ~Core(); void appInit(); int getAuth(); public slots: void appExit(); private slots: void appMenuTriggered(QAction *action); private: void preInit(); MainWindow *mwnd; }; Core.cpp code Core::Core(QObject *parent) : QObject(parent) { qDebug() << "Core::Constructor called"; preInit(); } Core::~Core() { delete mwnd; qDebug() << "Core::Destructor called"; }

Pyside: Multiple QProcess output to TextEdit

試著忘記壹切 提交于 2019-12-24 10:35:39
问题 I have a pyside app that calls an exectuable. I want to run this executable asynchronously in n processes and capture the output of each process in a QTextEdit. At the moment I have: def run(self, args, worklist): self.viewer = OutputDialog(self) self.procs = [] for path in worklist: final_args = args + path p = QtCore.QProcess(self) p.readyReadStandardOutput.connect(self.write_process_output) self.procs.append(p) p.start(self.exe, final_args) def write_process_output(self): for p in self

Wait for a SLOT to finish the execution with Qt

折月煮酒 提交于 2019-12-24 04:25:14
问题 In my code I emit a signal (mySignal) and I want to wait for the end of a connected slot (mySlot) execution before it continues: emit mySignal(); // Wait for the end of mySlot execution... // Some code that has to be executed only after the end of mySlot execution... Is there a way to do so ? 回答1: If the sender and the receiver are in the same thread use Qt::DirectConnection , if they are in 2 different threads use Qt::BlockingQueuedConnection . ClassA a; ClassB b; ClassC c; c.moveToThread

Signal to slot connection: triggering signal iteratively inside a loop

对着背影说爱祢 提交于 2019-12-24 03:24:50
问题 Setting up ray-caster I add QRayCaster to my root entity and connect its signal to a slot: void MySceneClass::createRootEntity() { // ... // Add ray caster to root entity m_rayCaster = new Qt3DRender::QRayCaster(m_rootEntity); m_rayCaster->setRunMode(Qt3DRender::QAbstractRayCaster::SingleShot); m_rootEntity->addComponent(m_rayCaster); // Set up signal to slot connection QObject::connect(m_rayCaster, &Qt3DRender::QRayCaster::hitsChanged, this, &MySceneClass::handleRayCasterHits); // ... } I

Qt Connect signals with different arguments

僤鯓⒐⒋嵵緔 提交于 2019-12-24 03:03:27
问题 I have a simple question guys, reading the thread about connecting signals with slots with fewer arguments, and of course, the Qt documentation. However, I do not need to connect signals with slots. I actually want to connect signals with signals with fewer arguments . The documentation is very clear about slots, but what about signals? Is that considered safe? Thanks & Cheers! 回答1: There is no difference. The receiving signal may have a shorter signature than the emitting signal. because it

Efficiency of Qt Signals and Slots

与世无争的帅哥 提交于 2019-12-24 02:25:36
问题 I was browsing the methods inside of QMainWindow and noticed that some parts (such as resizeEvent and winEvent) are not implemented as signals but rather you have to inherit this class to be able to override them. My question is, how efficient are signals and slots and would it be possible to implement these types of functions as signals from which other classes can subscribe to. For instance, inside of a high performance game engine. 回答1: From what I recall, Trolltech stated that a signal

Can I create a new style pyqt signal that isn't a field member of a class?

痞子三分冷 提交于 2019-12-24 01:52:42
问题 So for the only way that I can see to create a style signal with PyQt4 is as follows: class MyCustomClass(QtCore.QThread): custom_signal = QtCore.pyqtSignal(str) My beef is if I declare that signal anywhere else, pyqt throws an error at me about how custom_signal doesn't have a connect() function. I would like to create a helper function to help remove the boilerplate/repeated code when I want to do something as simple as: starting a new thread, doing work in that thread, sending the result

Can I create a new style pyqt signal that isn't a field member of a class?

爷,独闯天下 提交于 2019-12-24 01:52:07
问题 So for the only way that I can see to create a style signal with PyQt4 is as follows: class MyCustomClass(QtCore.QThread): custom_signal = QtCore.pyqtSignal(str) My beef is if I declare that signal anywhere else, pyqt throws an error at me about how custom_signal doesn't have a connect() function. I would like to create a helper function to help remove the boilerplate/repeated code when I want to do something as simple as: starting a new thread, doing work in that thread, sending the result

Qt: Connect inside constructor - Will slot be invoked before object is initialized?

白昼怎懂夜的黑 提交于 2019-12-23 20:17:41
问题 I am learning Qt framework (C++) and was wondering if QT has any mechanisms to protect slots from being called before an object is fully initialized. Consider Class A constructor: A::A() { mTreeView = new QTreeView(); ... connect(mTreeView, &QTreeView::customContextMenuRequested, this, &A::OnContextMenuRequested); ... } My worry is the user would be able to right-click on the tree-view before A's constructor has finished. Another context is as follows: A::A() { mQObj = new MyQObject();

In Qt many slots connected to the same signal, do they invoke in order when emit the signal?

谁说胖子不能爱 提交于 2019-12-23 12:46:30
问题 In the Qt document it is said: if several slots are connected to one signal, the slots will be executed one after the other, in the order they have been connected, when the signal is emitted. But in the connect() function, setting the Qt::ConnectionType type as Qt::QueuedConnection means "The slot is invoked when control returns to the event loop of the receiver's thread. The slot is executed in the receiver's thread." and Qt::DirectConnection means "the slot is invoked immediately, when the