Results 1 to 2 of 2

Thread: Why the signal "dataChanged" by QTableWidget not work?

  1. #1

    Default Why the signal "dataChanged" by QTableWidget not work?

    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):
    Qt Code:
    1. MainWindow::MainWindow()
    2. {
    3. QMenu *fileMenu = new QMenu(tr("&File"), this);
    4. QAction *openAction = fileMenu->addAction(tr("&Open..."));
    5. openAction->setShortcuts(QKeySequence::Open);
    6. QAction *saveAction = fileMenu->addAction(tr("&Save As..."));
    7. saveAction->setShortcuts(QKeySequence::SaveAs);
    8. QAction *quitAction = fileMenu->addAction(tr("E&xit"));
    9. quitAction->setShortcuts(QKeySequence::Quit);
    10.  
    11. setupModel();
    12. setupViews();
    13.  
    14. connect(openAction, SIGNAL(triggered()), this, SLOT(openFile()));
    15. connect(saveAction, SIGNAL(triggered()), this, SLOT(saveFile()));
    16. connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
    17. connect (model,SIGNAL(dataChanged(const QModelIndex & topLeft, const QModelIndex & bottomRight)),this,SLOT(display(const QModelIndex & topLeft, const QModelIndex & bottomRight)));
    18. menuBar()->addMenu(fileMenu);
    19. statusBar();
    20.  
    21. openFile(":/Charts/qtdata.cht");
    22.  
    23. setWindowTitle(tr("Chart"));
    24. resize(870, 550);
    25. }
    To copy to clipboard, switch view to plain text mode 
    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:
    Qt Code:
    1. void display(const QModelIndex & topLeft, const QModelIndex & bottomRight);
    To copy to clipboard, switch view to plain text mode 

    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.
    Last edited by wysota; 20th August 2011 at 09:35. Reason: missing [code] tags

  2. #2

    Default Re: Why the signal "dataChanged" by QTableWidget not work?

    I understand, It should be

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

    Then it works.

Similar Threads

  1. Why this doesn't work? qDebug() << "Test" << std::endl;
    By grayfox in forum Qt Programming
    Replies: 4
    Last Post: 1st June 2011, 10:19
  2. QProgressBar "crash" - doesn't work properly
    By metRo_ in forum Qt Programming
    Replies: 6
    Last Post: 23rd October 2010, 13:56
  3. Translation QFileDialog standart buttons ("Open"/"Save"/"Cancel")
    By victor.yacovlev in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2008, 19:05
  4. Hasn't QTableWidget an "activated" signal?
    By Morea in forum Qt Programming
    Replies: 1
    Last Post: 19th September 2007, 01:53
  5. Signal defined in "a.h" can not emit in "b.cpp"
    By Shawn in forum Qt Programming
    Replies: 9
    Last Post: 21st May 2007, 16:55

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.