PDA

View Full Version : Why the signal "dataChanged" by QTableWidget not work?



Tao Clark
20th August 2011, 07:53
Hello, I am modifying the example "Chart" so that when I change data in the table, another function "Display()" can be executed. Below is my modification to MainWindow.cpp (line #17 is added to the original code):

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);
}

I am therefore expecting the following function written by my own (and added to prive slot in MainWindow.h) will be executed once I change data in the table view:

void display(const QModelIndex & topLeft, const QModelIndex & bottomRight);

However, I found whatever I did to the data in the table view during execution of the main program, the display() function would never be triggered. Could anyone help me with this. I am using Qt 4.7 with visual studio 2008. Thank you very much.

Tao Clark
20th August 2011, 18:16
I understand, It should be

connect(model, SIGNAL(dataChanged ( const QModelIndex &, const QModelIndex & )),
this, SLOT( backgroundChanged ( const QModelIndex & , const QModelIndex & )));

Then it works.