You can create custom signal in your classA, for example buttonClicked(), that will be emitted whenever ui->button clicked() signal is emitted. So, you can connect buttonClicked() signal from classA instance to F() slot from classB instance without classB instance to be a member of classA.
Or you can create a function that return a pointer to ui->button.
{
Q_OBJECT
public:
~classA();
signals:
void buttonClicked();
private:
Ui::board *ui;
};
{
ui->setupUi(this);
connect(ui->button, SIGNAL(clicked()), this, SIGNAL(buttonClicked()));
}
{
return ui->button;
}
class classA : public QWidget
{
Q_OBJECT
public:
classA(QWidget *parent = 0);
QPushButton *button();
~classA();
signals:
void buttonClicked();
private:
Ui::board *ui;
};
classA::classA(QWidget *parent) : QWidget(parent), ui(new Ui::board)
{
ui->setupUi(this);
connect(ui->button, SIGNAL(clicked()), this, SIGNAL(buttonClicked()));
}
QPushButton* classA::button()
{
return ui->button;
}
To copy to clipboard, switch view to plain text mode
{
Q_OBJECT
public:
~classB();
public slots:
void F();
};
class classB: public QWidget
{
Q_OBJECT
public:
classB(QWidget *parent = 0);
~classB();
public slots:
void F();
};
To copy to clipboard, switch view to plain text mode
classA a;
classB b;
QObject::connect(&a,
SIGNAL(buttonClicked
()),
&b,
SLOT(F
()));
// or
QObject::connect(a.
button(),
SIGNAL(clicked
()),
&b,
SLOT(F
()));
classA a;
classB b;
QObject::connect(&a, SIGNAL(buttonClicked()), &b, SLOT(F()));
// or
QObject::connect(a.button(), SIGNAL(clicked()), &b, SLOT(F()));
To copy to clipboard, switch view to plain text mode
Bookmarks