signals-slots

What is a difference between these two clicked() signals in PyQt?

牧云@^-^@ 提交于 2019-12-02 22:09:56
问题 QtCore.QObject.connect(my_button, QtCore.SIGNAL('clicked()'), my_func) and my_button.clicked.connect(my_func) I usually use the first option, but then I found the second one and want to know what is a difference between them. 回答1: The first option is the old-style signal and slot syntax, which is now obsolete. You can still use it in PyQt4, but it is not supported at all in PyQt5. The second option is the new-style signal and slot syntax, which can be used in PyQt5 and all recent versions of

applying python functions directly to Qt designer as signals

南楼画角 提交于 2019-12-02 21:07:24
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 output to z. Is there any way to do this directly in Qt Designer by adding the function f(x,y) written

Using QSlider to change the value of a variable

不羁岁月 提交于 2019-12-02 16:38:03
问题 I'm trying to use QSlider to change the value of a variable, #include <QSlider> class MainThread : public QWidget{ Q_OBJECT public: MainThread(QWidget *parent=0); private slots: void setValue(double); private: QSlider *slider; }; MainThread::MainThread(QWidget *parent):QWidget(parent){ slider = new QSlider(Qt::Horizontal,0); connect(&slider, SIGNAL((slider->valueChanged())), this, SLOT(setValue(double))); // here's my problem ... } My question is how can I connect the SIGNAL of the slider to

Slot seemingly not recognized in Qt app [duplicate]

早过忘川 提交于 2019-12-02 13:27:31
This question already has an answer here: C++ Qt signal and slot not firing 3 answers I have been working on learning C++ and Qt4 recently, but I have hit a stumbling block. I have the following class and implementation: class Window : public QWidget { public: Window(); public slots: void run(); private: //... }; and Window::Window() { //... connect(runBtn,SIGNAL(clicked()),this,SLOT(run())); //... } Window::run() { //... } However, when I attempt to build and run it, although it builds just fine, it immediately exits out with the message Object::connect: No such slot QWidget::run() Unless I

Launching multiple threads and restarting them

孤者浪人 提交于 2019-12-02 12:59:24
问题 I'm trying to program a system where I create x amount of worker threads. These threads will finish their work in different times. When any of them complete their work, I will examine their output and restart them again (Keeping the running number of threads around x). I will do this for a number of aribitary iterations. So, basically a controller thread will launch x amount of threads, and will restart them when they finish their work, until some number of iterations are reached. Additional

It is possible connect a QML Object existing signal in C++ QObject::connect()?

我是研究僧i 提交于 2019-12-02 10:45:02
问题 The QML TreeView has an signal named: doubleClicked(QModelIndex) ref: https://doc.qt.io/qt-5.10/qml-qtquick-controls-treeview.html#doubleClicked-signal Its possible connect that existing signal in a C++ QObject::connect() ?? I tried this: QQmlApplicationEngine engine; QObject *myTreeMenu = engine.rootObjects().at(0)->findChild<QObject*>("myTreeMenu"); connect(myTreeMenu , SIGNAL(doubleClicked(QModelIndex)), this, SLOT(slotModelClicked(QModelIndex))); But i receive this return error: QObject:

What is a difference between these two clicked() signals in PyQt?

时间秒杀一切 提交于 2019-12-02 10:40:47
QtCore.QObject.connect(my_button, QtCore.SIGNAL('clicked()'), my_func) and my_button.clicked.connect(my_func) I usually use the first option, but then I found the second one and want to know what is a difference between them. The first option is the old-style signal and slot syntax , which is now obsolete. You can still use it in PyQt4, but it is not supported at all in PyQt5. The second option is the new-style signal and slot syntax , which can be used in PyQt5 and all recent versions of PyQt4 (it was introduced in v4.5). The PyQt docs lists the following disadvantages of the old-style syntax

How to tell the mouse button using QApplication::mouseButtons() in a “click” slot?

心不动则不痛 提交于 2019-12-02 10:04:52
I have a QMainWindow, and want to handle the "clicked" signal from a smaller widget (such as tableview) inside it. Originally I connect the signal to a slot of this QMainWindow, this is the most common approach. Now I need to tell which mouse button is clicked, and do different things for left and right button, I found that the "clicked" signal don't have the mouse event information. I tried to implement the "mousePressEvent" function,but there are still some problem. if the mouse action is acted on the smaller widget, the MainWindow won't go into its mousePressEvent. Some document says that

Invoke slot asynchronously without connecting to it using clear line of code

扶醉桌前 提交于 2019-12-02 08:41:17
问题 I have encountered quite freaky bug - QAction::trigger caused blocking dialog to appear, which caused my server which called trigger to go stuck (eg. not able to process socket signals until dialog was closed). I figured out a workaround. I connect signal void triggerWorkaround() to slot QAction::trigger using Qt::QueuedConnection and I emit it: QObject::connect(this, &HackClass::triggerWorkaround, targetAction_.data(), &QAction::trigger, Qt::QueuedConnection); emit triggerWorkaround();

It is possible connect a QML Object existing signal in C++ QObject::connect()?

∥☆過路亽.° 提交于 2019-12-02 05:16:26
The QML TreeView has an signal named: doubleClicked(QModelIndex) ref: https://doc.qt.io/qt-5.10/qml-qtquick-controls-treeview.html#doubleClicked-signal Its possible connect that existing signal in a C++ QObject::connect() ?? I tried this: QQmlApplicationEngine engine; QObject *myTreeMenu = engine.rootObjects().at(0)->findChild<QObject*>("myTreeMenu"); connect(myTreeMenu , SIGNAL(doubleClicked(QModelIndex)), this, SLOT(slotModelClicked(QModelIndex))); But i receive this return error: QObject::connect: No such signal TreeView_QMLTYPE_63_QML_68::doubleClicked(QModelIndex) in '...' QObject: