signals-slots

Why is PyQt executing my actions three times?

こ雲淡風輕ζ 提交于 2019-12-03 15:49:20
I'm still kind of new to PyQt but I really have no idea why this is happening. I have a Mainwindow that I create like this: class MainWindow(QtGui.QMainWindow): #initialize def __init__(self): #Call parent constructor super(MainWindow, self).__init__() #Load the interface self.ui = uic.loadUi(r"Form Files/rsleditor.ui") #Show the ui self.ui.show() and when I wanted to override the close event with: def closeEvent(self, event): quit_msg = "Are you sure you want to exit the program?" reply = QtGui.QMessageBox.question(self, 'Message', quit_msg, QtGui.QMessageBox.Yes, QtGui.QMessageBox.No) if

Qt thread does not stop after calling exit/quit

牧云@^-^@ 提交于 2019-12-03 15:48:29
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::doit() { qDebug("[%d] emitting...", (int) QThread::currentThreadId()); emit x(); } int main(int argc,

qt signal undefined reference error

試著忘記壹切 提交于 2019-12-03 15:41:30
问题 I have a class server for which I have created a signal joined(QString name). I call it in a function called join(QString name), however I'm getting the error Server.o: In function Server::join(QString)': Server.cpp:(.text+0x48): undefined reference to Server::joined(QString)' collect2: ld returned 1 exit status This is what my header file looks like: #ifndef SERVER_H #define SERVER_H #include <QString> #include <mqueue.h> #include <QVector> #include <QStringList> #include "../src/messages.h"

What are some best practices for debugging Qt signals and slots?

 ̄綄美尐妖づ 提交于 2019-12-03 15:01:16
问题 Debugging signals and slots can be hard, because the debugger does not jump to the slots of a signal when it is emitted. What are some best practices for debugging Qt signals and slots? In particular How do I make sure connections are set up successfully? When should I use signals and slots, when should I avoid them? What are the most efficient debugging techniques from your experience? 回答1: There was a blog post written a while back called 20 ways to debug Qt signals and slots It addresses I

Swing - replacement for Qt signal/slots

妖精的绣舞 提交于 2019-12-03 14:44:26
In Qt GUIs it is very convenient use signals & slots - it decouple events passing. When I create some widget that throw signal, I don't have to know in advance who can get it, and later with connect I specify connections. What is parallel in Java/Swing? Can you point to good resources on this issue? trashgod If none of the existing EventListener implementations meet your requirements, you can create your own custom event. Every JComponent contains a field of type EventListenerList . You can use the approach outlined in the EventListenerList API to enable your custom JComponent subclass to fire

How to use templates with QT signals and slots?

 ̄綄美尐妖づ 提交于 2019-12-03 13:12:49
I want to use signals and slots in my program, but unfortunately they should be used for transmitting several different data types (e.g. QString, double, etc.) and I don't want to write twenty different slots just because I need one for each data type. But when I want to declare a slot like template <typename t> void Slot1(t data); QT tells me that it is not possible to use templates in signals and slots. Is there a workaround? Or can my approach simply improved? Accurate answer: It is impossible Workaround: You can do something like this with new signals and slots syntax: QSlider *slid = new

How to disconnect a signal with a slot temporarily in Qt?

て烟熏妆下的殇ゞ 提交于 2019-12-03 05:48:35
问题 I connect a slot with a signal. But now I want to disconnect them temporarily. Here is part of my class declaration: class frmMain : public QWidget { ... private: QTimer *myReadTimer; ... private slots: void on_btnDownload_clicked(); ... }; In the constructor of frmMain , I connect myReadTimer with a slot so that ReadMyCom will be called every 5 seconds: myReadTimer=new QTimer(this); myReadTimer->setInterval(5000); connect(myReadTimer,SIGNAL(timeout()),this,SLOT(ReadMyCom())); But, in slot on

qt signal undefined reference error

那年仲夏 提交于 2019-12-03 05:14:42
I have a class server for which I have created a signal joined(QString name). I call it in a function called join(QString name), however I'm getting the error Server.o: In function Server::join(QString)': Server.cpp:(.text+0x48): undefined reference to Server::joined(QString)' collect2: ld returned 1 exit status This is what my header file looks like: #ifndef SERVER_H #define SERVER_H #include <QString> #include <mqueue.h> #include <QVector> #include <QStringList> #include "../src/messages.h" class Server { public: Server(); void start(); private: void join(QString name); char buf[MSG_SIZE],

What are some best practices for debugging Qt signals and slots?

心已入冬 提交于 2019-12-03 03:47:32
Debugging signals and slots can be hard, because the debugger does not jump to the slots of a signal when it is emitted. What are some best practices for debugging Qt signals and slots? In particular How do I make sure connections are set up successfully? When should I use signals and slots, when should I avoid them? What are the most efficient debugging techniques from your experience? jdi There was a blog post written a while back called 20 ways to debug Qt signals and slots It addresses I think #1 and #3 of your questions. For #2, I don't think there is really a hard and fast reason to use

Does Qt support virtual pure slots?

拥有回忆 提交于 2019-12-03 01:45:34
问题 My GUI project in Qt has a lot of "configuration pages" classes which all inherit directly from QWidget . Recently, I realized that all these classes share 2 commons slots ( loadSettings() and saveSettings() ). Regarding this, I have two questions: Does it make sense to write a intermediate base abstract class (lets name it BaseConfigurationPage ) with these two slots as virtual pure methods ? (Every possible configuration page will always have these two methods, so I would say "yes") Before