[solved] problem: Model::data() function never be called.
-
I created a UI interface based on QWidget by QtDesigner, inside the window, I put labels, buttons and a Tableview. The tablview is referenced by ui->Stepping view, I connect this view to the model I created, ui->SteppingView->setModel(&StepTableModel); the program can bu run. But tableview shows nothing, and the breakpoints I set in the function steptablemodel::data() never be reached. looks like it never call steptablemodel::data() funtion. I do not know what causes the problem. thanks for help.
**** update: thanks for Lykurg's help.
@
RemoteContol::RemoteContol(QWidget *parent) :
QWidget(parent),
ui(new Ui::RemoteContol)
{
QStringList a;
ui->setupUi(this);connect(ui->UpdateButton,SIGNAL(clicked()),this,SLOT(sendSettingParameters())); udpSocket.bind(QHostAddress("10.10.10.11"),49166); connect(&udpSocket, SIGNAL(readyRead()), this, SLOT(processPendingData())); connect(ui->GPSradioButton, SIGNAL(toggled(bool)), this, SLOT(baseTimeToggled())); connect(ui->ManualradioButton, SIGNAL(toggled(bool)), this, SLOT(opModeToggled())); connect(ui->FDradioButton, SIGNAL(clicked()), this, SLOT(waveformToggled())); connect(ui->TD50radioButton, SIGNAL(clicked()), this, SLOT(waveformToggled())); connect(ui->TD33radioButton, SIGNAL(clicked()), this, SLOT(waveformToggled())); connect(ui->TD25radioButton, SIGNAL(clicked()), this, SLOT(waveformToggled())); connect(ui->FreqSetcomboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(freqprodChanged(int))); CurrentDateTime= QDateTime::fromString("20000101","yyyyMMdd"); ui->DatetimeLCD->display("2000-01-01 00:00:00"); oldtimeflag=0; baseTime = 0; opMode = 0; waveform = 0; a<<"aaa"<<"bbb"<<"ccc"; a<<"1aa"<<"b2b"<<"cc3"; steptablemodel StepTableModel(a); ui->SteppingView->setModel(&StepTableModel); ui->SteppingView->show();
}
class steptablemodel : public QAbstractTableModel
{
Q_OBJECT
public:
explicit steptablemodel(QObject *parent = 0);
steptablemodel(QStringList &tablelist, QObject *parent = 0);
int rowCount(const QModelIndex &parent) const;
int columnCount(const QModelIndex &parent) const;
QVariant data(const QModelIndex &index, int role) const;signals:
public slots:
private:
QStringList stepTable;
}QVariant steptablemodel::data(const QModelIndex &index, int role) const
{
if (!index.isValid()) return QVariant();if(index.row() >= stepTable.size() || index.row() < 0) return QVariant(); if (role == Qt::DisplayRole) { return stepTable.at(index.row()*columnCount(index)+index.column()); } return QVariant();
}@