closeEvent not called for QWidget from plugin - qt

I create a QWidget in a plugin. I also use a QTimer so showing some data depends of time. When my QWidget is closed is must delete this QTimer but i can not because closeEvent is not called. What can be the problem ?

If by closed you mean destroyed, then you can connect the QWidget's destroyed() signal to the QTimer's destroy() slot.

Related

How to link a slot in the code with a QWidget in mainwindow

I am a beginner with signal & slots in QtCreator.
I would like to know how to connect a signal declared in mainwindow code in a Qwidget LCDNumber include in the mainwindow.
Because even if my ManWindow signal is diclared correctly (I guess)
I can't configure the connection between MainWindow signal and LDCNumber Display(int) SLOT it in design mode :
Would you know how to code the connection of MainWindow SIGNAL declared in MinWindow's Class and LCDNumber include in Mainwindow's SLOT, please?
Here are all the propeties of QLCDNumber class :
Thanks a lot!!

Qt emit signal after widget is closed

I have a child QDialog, when a button is pressed from it a socket is opened from QtConcurrent, and if there's an error an alert dialog is shown.
But if the user closes the child QDialog to return to the main window the signal cannot be received by the child QDialog slot.
I tried to broadcast the signal to parentWidget, but the program crashes, because this->parentWidget() doesn't exist anymore.
I use this code to emit the signal and connect it to the slot
connect(this, SIGNAL(errorTcpSignal(QString)), this, SLOT(displayTcpError(QString)));
connect(&t, QOverload<QAbstractSocket::SocketError>::of(&QAbstractSocket::error),[=](QAbstractSocket::SocketError err){
emit errorTcpSignal("Error while changing game settings \n" + QVariant::fromValue(err).toString());
});
Is there a way to solve this issue?
Thank you very much.
SOLVED:
emit the signal from the child widget, but set the connection from the father widget.

QToolButton released() signal fired twice

I make a color picker based on Qt 5.4.1. It works as this: when user clicked one QToolButton, it shows the QColorDialog. I use the QToolButton's 'released()' signal. Now the problem is, when I close the QColorDialog, the released() signal fired again. But when I change it to QPushButton, the problem gone.
My toolbutton has no menu with it. I wonder if QToolButton is designed as this, or it's just a bug? Because other reason, I can't use QPushButton. So, is there some workround to make toolbutton work?
Update:
I tried put only the code below in the released slot:
static int n = 0;
qDebug() << Q_FUNC_INFO << ++n;
return;
the counter is increased 2 every click. So it should has nothing with the QColorDialog.
I finally find the reason. I've never noticed Qt has the ability to connect signals and slots automatically. That is, QMetaObject::connectSlotsByName(). I accidently give my slot a name like
void on_<object name>_<signal name>(<signal parameters>);
style, this is just the style what "QMetaObject::connectSlotsByName()" needed. So, Qt automatically connect the released() signal to my slot. And I manually connect them too. In Qt, connect a signal twice, it will fire twice, even the sender and receiver is the same!!!!

Is Hidden QWidget object receives signals

Simple Query:
If GUI widget window is hidden does it receives signals from other objects?
In our Qt application we have seen this issue/behaviour.
However, when window is shown it receives and process all the signals that it receives.
Every QObject (and hense every QWidget) receives signals until it's destroyed or the signal is disconnected. Visibility doesn't matter.
If you don't disconnect signals while hiding the QWidget they're received and processed.

How to connect QPushButton to a promoted QWidget?

I have a QWidget container that contains my custom widget. This QWidget container was promoted to the custom widget I created. I have a QPushButton on my MainWindow.ui. I want to connect this QPushButton to the promoted QWidget. How will I do this?
For example, I have a function on my promoted QWidget class, and I want to call this function when I click the QPushButton located at the MainWindow.ui.
Thanks in advance!
Have you considered using a connect??
connect the QPushButton singal clicked to that function (make sure its a slot where its declared).

Resources