C++ (Qt)MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow){ ui->setupUi(this); QObject::connect(ui->tableWidget, SIGNAL(itemChanged(QTableWidgetItem*)), SLOT(changed(QTableWidgetItem*))); QObject::connect(ui->tableWidget, SIGNAL(cellChanged(int,int)), SLOT(changed(int,int)));} MainWindow::~MainWindow(){ delete ui;} void MainWindow::changed(QTableWidgetItem *item) { qDebug() << QString("Элемент [%1, %2] %3 был изменен.").arg(item->row()).arg(item->column()).arg(item->text());}void MainWindow::changed(int row, int column) { qDebug() << QString("Ячейка [%1, %2] была изменена.").arg(row).arg(column);}
void MainWindow::changed(QTableWidgetItem *item) { item->setText("!!!");}
void MainWindow::changed() { QTableWidgetItem *item; l=item->text();}
void MainWindow::changed(QTableWidgetItem *item) { QString text_cell = item->text(); ...}
void MainWindow::changed(QTableWidgetItem *item) { QString text_cell = item->text(); int l = text_cell.toInt(); ...}
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow){ ui->setupUi(this); ui->tableWidget->setFrameStyle(3); ui->tableWidget->setColumnCount(3); ui->tableWidget->setRowCount(3); ui->tableWidget->setHorizontalHeaderLabels(QStringList()<< "l,см" << "Т,c" << "v,Гц" ); QObject::connect(ui->tableWidget, SIGNAL(itemChanged(QTableWidgetItem*)), SLOT(changed(QTableWidgetItem*))); QObject::connect(ui->tableWidget, SIGNAL(cellChanged(int,int)), SLOT(changed(QTableWidgetItem *item))); for(int row = 0; row < ui->tableWidget->rowCount(); row++) for(int column = 1; column < 2; column++) { T=2*pi*sqrt(d/g); QTableWidgetItem *item = new QTableWidgetItem(); item->setText(QString("%1").arg(T)); ui->tableWidget->setItem(row, column, item); }}MainWindow::~MainWindow(){ delete ui;}void MainWindow::changed(QTableWidgetItem *item){ QString text_cell = item->text(); d = text_cell.toInt(); }
namespace Ui {class MainWindow;}class MainWindow : public QMainWindow{ Q_OBJECTpublic: explicit MainWindow(QWidget *parent = 0); ~MainWindow();private slots: //void on_pushButton_clicked(); void changed(QTableWidgetItem*);private: float T,g,pi; int d; QString l,l1; Ui::MainWindow *ui;};