C++ (Qt)#ifndef FIELD_H#define FIELD_H#include <QWidget>#include <QTableWidget>#include <QHeaderView>#include <QObject> class field : public QObject{ Q_OBJECT public: field(QWidget * i,int x, int y, int BeginSize); QTableWidget * tablewidget; public slots: int waitValue(); }; #endif // FIELD_H
C++ (Qt)#include "field.h" field::field(QWidget * parent,int x, int y, int BeginSize){ int i, NumCellsOfField = 10, CorrectSize = 2, FieldSize = BeginSize+CorrectSize; tablewidget = new QTableWidget(parent); tablewidget->setGeometry(x,y,FieldSize,FieldSize); //положение и размер поля tablewidget->setRowCount(NumCellsOfField); tablewidget->setColumnCount(NumCellsOfField); //поле 10 x 10 циклом for (i=0;i!=NumCellsOfField;i++) { tablewidget->setRowHeight(i,BeginSize/NumCellsOfField); tablewidget->setColumnWidth(i,BeginSize/NumCellsOfField); } connect(tablewidget,SIGNAL(cellClicked(int,int)),this, SLOT(waitValue()));} int field::waitValue(){ tablewidget->setItem(0, 3, new QTableWidgetItem); tablewidget->item(0, 3)->setBackground(Qt::red); return 0;}
C++ (Qt)int foo(){ return 0;}
C++ (Qt)connect(tablewidget, &QTableWidget::cellClicked, this, &field::waitValue);
C++ (Qt)connect(tablewidget, &QTableWidget::cellClicked, [&]{qDebug() << "lambda";});