QT6 - signal/slot between 2 classes
CASE 1: Not creating button in UI file:
In your class MainWindow
, variable MyPushButton
is a local variable that gets destroyed after it end its scope in constructor. You need to create a dynamic variable of pushButton
like this:
pushbutton *MyPushButton = new pushButton(this);
connect(MyPushButton, SIGNAL(pb_isChecked()), this, SLOT(MainWindowPBClicked()), Qt::DirectConnection);
CASE 2: Creating button in UI file:
In this case you cannot use your custom signal pb_isChecked()
. You will need to use standard QPushButton
signal such as clicked()
connect(ui->MyPushButton, SIGNAL(clicked()), this, SLOT(MainWindowPBClicked()), Qt::DirectConnection);