I have class MainWindow
that will contain several QWidgetTables with their own headers and other members. For now, I would like to define custom table classes within class MainWindow
because they are pretty simple. See Example below:
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(SSHClient &client, QWidget *parent = 0);
public slots:
struct Workflow_Table {
QTableWidget* widget;
QStandardItemModel model;
QStringList headers;
void addRow(){}
void removeRow(){}
} workflow_table;
private:
SSHClient& client;
Ui::MainWindow* ui;
CTL ctl;
};
Within Ui::MainWindow
I have QPushButtons to add and remove rows for workflow_table
. I would like to connect these QPushButton::clicked
signals to
MainWindow::Workflow_Table::addRow
, but I haven't had any success, nor do I know if what I'm attemping is even possible.
MainWindow::MainWindow(SSHClient &client, QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
client(client)
{
ui->setupUi(this);
//class CTL is a not a QObject class, yet std::bind causes it to act like a slot here. This statement compiles and runs fine.
connect(ui->button_load_ctl, &QPushButton::clicked, this, std::bind(&CTL::saveas, &ctl, "saved.ctl"));
//Error: 3 Arguments provided - 4 Expected. I'm almost certain this won't work.
connect(ui->button_add, &QPushButton::clicked, this, &MainWindow::Workflow_Table::addRow);
//Error: Not a signal or slot declaration. Not sure why this isn't working.
connect(ui->button_add, &QPushButton::clicked, this, std::bind(&MainWindow::Workflow_Table::addRow, &workflow_table));
//This doesn't work either. Error 1.
connect(ui->button_add, &QPushButton::clicked, this, std::bind(&Workflow_Table::addRow, &workflow_table));
}
Is it possible that I can connect MainWindow::Workflow_Table::addRow
(without making Workflow_Table a QObject) to a QPushButton::clicked
signal from MainWindow?
The easy solution is to make Workflow_Table
a QObject, but I'm curious if I can still connect the Workflow_Table's functions since they're defined under the scope of a QObject. I have been able to connect other non-slot functions by using std::bind like the CTL::saveas
function so I would think I can do something similar here. I have also tried moving Workflow_Table
under the public
and public slots
access specifiers but neither has worked.