我修改了一下QT官网上的Chart的例子,在MainWindow.CPP中加入(粗体标出):
MainWindow::MainWindow()
{
QMenu *fileMenu = new QMenu(tr("&File"), this);
QAction *openAction = fileMenu->addAction(tr("&Open..."));
openAction->setShortcuts(QKeySequence::Open);
QAction *saveAction = fileMenu->addAction(tr("&Save As..."));
saveAction->setShortcuts(QKeySequence::SaveAs);
QAction *quitAction = fileMenu->addAction(tr("E&xit"));
quitAction->setShortcuts(QKeySequence::Quit);
setupModel();
setupViews();
connect(openAction, SIGNAL(triggered()), this, SLOT(openFile()));
connect(saveAction, SIGNAL(triggered()), this, SLOT(saveFile()));
connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
connect (model,SIGNAL(dataChanged(const QModelIndex & topLeft, const QModelIndex & bottomRight)),this,SLOT(display(const QModelIndex & topLeft, const QModelIndex & bottomRight)));
menuBar()->addMenu(fileMenu);
statusBar();
openFile(":/Charts/qtdata.cht");
setWindowTitle(tr("Chart"));
resize(870, 550);
}
我是想程序执行的时候如果修改了Table中的数据,则能够触发
void display(const QModelIndex & topLeft, const QModelIndex & bottomRight);
这个我写的函数,但是发现程序执行的时候,无论我在表中怎么修改,都不会执行display(),请问这是为什么呢?
期盼有高手帮我解答下这个问题。谢谢!