大家好
我现在有一个tableWidget, 它显示一些数据并计算这些数据的最大值,最小值以及平均值。 我还添加了一个reset按钮,如果点击它这个列表当中的所有数据都应当被重置。但是响应事件不起作用。。。已经试了两天了还是没有什么眉目,跪求大神帮助。 以下是代码:
#include "tablewindow.h"
#include "preferences.h"
#include "averager.h"
#include "naturalStringCompare.h"
#include <QDateTime>
#include <QDebug>
#include <QPen>
TableWindow::TableWindow(Preferences &prefs, QWidget *parent) :
QDialog(parent)
{
wantScBeforeOthers = prefs.scBeforeOthers();
labelFont = prefs.labelFont();
QFontMetrics fm(labelFont);
labelFontWidth = fm.width(" 00:00:00 ");
mainLayout = new QVBoxLayout;
index = 0;
avg = 0.0;
min = 100;
max = 0;
isResetted = false;
// Set up the colors (Ericsson Brand colors as of 2013)
brandColors = new QList<QColor>;
brandColors->append(QColor(0xFF00285F));
brandColors->append(QColor(0xFF7B0663));
brandColors->append(QColor(0xFFE32119));
brandColors->append(QColor(0xFFF08A00));
brandColors->append(QColor(0xFFFABB00));
brandColors->append(QColor(0xFF89BA17));
brandColors->append(QColor(0xFF00625F));
brandColors->append(QColor(0xFF00A9D4));
brandColors->append(QColor(0xFF000000));
brandColors->append(QColor(0xFF333333));
brandColors->append(QColor(0xFFB1B3B4));
brandColors->append(QColor(0xFF0066B3));
tableWidget = new QTableWidget();
tableWidget->setColumnCount(5);
QStringList labels;
labels.push_back("Name");
labels.push_back("Value");
labels.push_back("Avg.");
labels.push_back("Min.");
labels.push_back("Max.");
tableWidget->setHorizontalHeaderLabels(labels);
pal = new QPalette(palette());
pal->setColor(QPalette::Window, Qt::white);
setPalette(*pal);
setAutoFillBackground(true);
QSize sz = tableWidget->size();
resize(sz.width() + 20, sz.height() + 20);
qDebug() << "###Resizing to " << sz;
mainLayout->addWidget(tableWidget);
buttonLayout = new QHBoxLayout;
reset_PB = new QPushButton("Reset");
space = new QLabel();
resetTime = new QLabel("Last reset at ...");
buttonLayout->addWidget(reset_PB);
buttonLayout->addWidget(space);
buttonLayout->addWidget(resetTime);
mainLayout->addLayout(buttonLayout);
if (prefs.showHost())
{
this->setWindowTitle("Loadmeter -- " + prefs.port());
}
else
{
this->setWindowTitle("Loadmeter");
}
this->setLayout(mainLayout);
connect(reset_PB, SIGNAL(clicked()), this, SLOT(resetData(SimpleDataNode dataset)));
}
void TableWindow::setupData(QStringList names)
{
QSet<QString> old_names_set = QSet<QString>::fromList(line_info.keys());
QSet<QString> new_names_set = QSet<QString>::fromList(names);
qDebug() << "Old names set: " << old_names_set;
qDebug() << "New names set: " << new_names_set;
if (new_names_set.unite(old_names_set).size() > old_names_set.size())
{
line_info.clear();
QStringList new_names = QStringList::fromSet(new_names_set.unite(old_names_set));
num_lines = new_names.length();
if (wantScBeforeOthers)