qt-signals

Difference between QObject::connect vs connect methods

跟風遠走 提交于 2019-11-30 17:36:18
I am a newbie with Qt. Most of the times Qt developers need to use signals and slots for object communication. I have seen two ways of connecting signals and slots so far. 1)QObject::connect(scrollBar, SIGNAL(valueChanged(int)),label, SLOT(setNum(int))); 2)connect(scrollBar, SIGNAL(valueChanged(int)),label, SLOT(setNum(int))); What is the exact difference between both of them? Why do we have to prefix QObject in the first method? lpapp You call the static version in both aforementioned cases, the signature of which is as follows: QMetaObject::Connection QObject::connect(const QObject * sender,

Using Qt signals and slots with multiple inheritance

被刻印的时光 ゝ 提交于 2019-11-30 13:10:29
I have a class ( MyClass ) that inherits most of its functionality from a Qt built-in object ( QGraphicsTextItem ). QGraphicsTextItem inherits indirectly from QObject . MyClass also implements an interface, MyInterface . class MyClass : public QGraphicsTextItem, public MyInterface I need to be able to use connect and disconnect on MyInterface* . But it appears that connect and disconnect only work on QObject* instances. Since Qt does not support multiple inheritance from QObject-derived classes, I cannot derive MyInterface from QObject . (Nor would that make much sense for an interface anyway.

How does QSignalMapper work?

…衆ロ難τιáo~ 提交于 2019-11-30 12:13:04
问题 After my post here : Associate signal and slot to a qcheckbox create dynamically I need to associate : • The signal clicked() when I click on a qCheckBox to my function cliqueCheckBox(QTableWidget *monTab, int ligne, QCheckBox *pCheckBox) To do so, I have to use QSignalMapper , after two hours of trying to understand how it works, I can't have a good result, here's the code I make, this is obviously wrong : QSignalMapper *m_sigmapper = new QSignalMapper(this); QObject::connect(pCheckBox,

How does QSignalMapper work?

浪尽此生 提交于 2019-11-30 04:14:01
After my post here : Associate signal and slot to a qcheckbox create dynamically I need to associate : • The signal clicked() when I click on a qCheckBox to my function cliqueCheckBox(QTableWidget *monTab, int ligne, QCheckBox *pCheckBox) To do so, I have to use QSignalMapper , after two hours of trying to understand how it works, I can't have a good result, here's the code I make, this is obviously wrong : QSignalMapper *m_sigmapper = new QSignalMapper(this); QObject::connect(pCheckBox, SIGNAL(mapped(QTableWidget*,int, QCheckBox*)), pCheckBox, SIGNAL(clicked())); QObject::connect(this, SIGNAL

Difference between QObject::connect vs connect methods

只谈情不闲聊 提交于 2019-11-30 01:26:04
问题 I am a newbie with Qt. Most of the times Qt developers need to use signals and slots for object communication. I have seen two ways of connecting signals and slots so far. 1)QObject::connect(scrollBar, SIGNAL(valueChanged(int)),label, SLOT(setNum(int))); 2)connect(scrollBar, SIGNAL(valueChanged(int)),label, SLOT(setNum(int))); What is the exact difference between both of them? Why do we have to prefix QObject in the first method? 回答1: You call the static version in both aforementioned cases,

Qt/C++: Signal for when a QListWidgetItem is checked?

与世无争的帅哥 提交于 2019-11-30 01:18:07
问题 In my form I have a QListWidget which contains checkable QListWidgetItems . I'm looking for a way to capture the event of a QListWidgetItem being checked/unchecked. I don't see any such signal existing for this but maybe I'm wrong. What I'm currently doing is using the QListWidget::itemClicked() signal and checking the checkState of the QListWidgetItem , but this isn't what I want because this event happens any time the item is clicked, not just went the checkmark is toggled. Can anyone give

Embedding Python3 in Qt 5

不羁的心 提交于 2019-11-29 19:09:33
问题 I would like to embed Python interpreter 3.4 into a Qt 5.2.1 application (64-bit). However I'm having build issues, I mean when I include Python header in the main.cpp it compiles fine. #include <python.h> #include "mainwindow.h" #include <QApplication> int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; w.show(); return a.exec(); } but when I put it anywhere else (after Qt headers) // // embedpytest.cpp // #include <QLibrary> #include <python.h> EmbedPyTest:

Using Qt signals and slots with multiple inheritance

六眼飞鱼酱① 提交于 2019-11-29 18:42:34
问题 I have a class ( MyClass ) that inherits most of its functionality from a Qt built-in object ( QGraphicsTextItem ). QGraphicsTextItem inherits indirectly from QObject . MyClass also implements an interface, MyInterface . class MyClass : public QGraphicsTextItem, public MyInterface I need to be able to use connect and disconnect on MyInterface* . But it appears that connect and disconnect only work on QObject* instances. Since Qt does not support multiple inheritance from QObject-derived

Qt 5 : update QProgressBar during QThread work via signal

那年仲夏 提交于 2019-11-29 08:51:23
I'm trying to update a QProgressDialog (owned by a QMainWindow class) along the execution of a QThread who process some time consuming operations. The thread emit some signals during operation in order to inform the calling app about progression. I'm looking to connect the progress signal emitted by the thread to the setValue slot of the QProgressDialog in order to update the progress bar. It doesn't work ! The progress dialog is not displayed. If I add a slot in my QMainWindow and connect it to the worker progress signal in order to display the value given by the thread throught qDebug output

Are signals in Qt automatically disconnected when one of the class is deleted

荒凉一梦 提交于 2019-11-29 02:48:27
Does Qt automatically remove connections between objects , when one of the side is deleted ? e.g connect (A .. , B ..) , when A (a pointer) is deleted , or B is deleted , will the connection be disconnected ? Is it necessary to use disconnect explicitly in destructor ? Yes, the QObject::~QObject destructor takes care of that: All signals to and from the object are automatically disconnected, and any pending posted events for the object are removed from the event queue. However, it is often safer to use deleteLater() rather than deleting a QObject subclass directly. Do take care though: Warning