When opening the dialog I've connected the dataChanged() signal to a slot which shows a debug message in the console. the connect() call returns true in debug.
{
...
connect(model, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)), this, SLOT(onModelsDataChanged(const QModelIndex&, const QModelIndex&)));
...
}
{
Q_UNUSED(topLeft);
Q_UNUSED(bottomRight);
qDebug() << "YES" << endl;
// model->loadFromFile(fileName); // fileName = path/to/value.csv
// ui->tableView->setModel(model);
}
{
...
connect(model, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)), this, SLOT(onModelsDataChanged(const QModelIndex&, const QModelIndex&)));
...
}
void Dialog::onModelsDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
{
Q_UNUSED(topLeft);
Q_UNUSED(bottomRight);
qDebug() << "YES" << endl;
// model->loadFromFile(fileName); // fileName = path/to/value.csv
// ui->tableView->setModel(model);
}
To copy to clipboard, switch view to plain text mode
The commented lines (reloading the model) didn't make any difference.
The button just increments a number when it's clicked and writes it to the file:
void Dialog::onButtonPush()
{
QFile log(":/value.csv");
x++;
if (log.
open(QFile::WriteOnly |
QFile::Truncate)) { stream << "Clicked button number;" << x << endl;
ui
->pushButton
->setText
(QString::number(x
));
}
log.flush();
log.close();
}
void Dialog::onButtonPush()
{
QFile log(":/value.csv");
QTextStream stream(&log);
x++;
if (log.open(QFile::WriteOnly | QFile::Truncate)) {
stream << "Clicked button number;" << x << endl;
ui->pushButton->setText(QString::number(x));
}
log.flush();
log.close();
}
To copy to clipboard, switch view to plain text mode
Button and tableview are on the same dialog window and the tableview is supposed to be updated as soon as the data changes - e.g. every time the button is clicked. The updating doesn't work though. :/
Bookmarks