我有非常简单的自定义模型,源自QStandardItemModel
. 函数rowCount
和columnCount
被多次调用,而其余函数都没有被调用,特别data()
是从未被调用。我找不到原因。
#include <IBAdditions/IB_events.h>
#include <QtGui/QStandardItemModel>
#include <QtGui/QStandardItem>
#include <QtCore/QtCore>
#include <vector>
/**
* model which allows for display
* of available data streams as tickers
*/
class TickerDisplayModel : public QStandardItemModel {
Q_OBJECT
public:
TickerDisplayModel(std::vector<IBAdditions::ContractEvent> availableTickers, QObject *parent = 0);
int rowCount(const QModelIndex &parent = QModelIndex()) const ;
int columnCount(const QModelIndex &parent = QModelIndex()) const;
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
bool setData(const QModelIndex & index, const QVariant & value, int role = Qt::EditRole);
Qt::ItemFlags flags(const QModelIndex & index) const;
private:
int m_;
int n_;
std::vector<IBAdditions::ContractEvent>& availableTickers_;
signals:
void editCompleted(const QString &);
};
这怎么叫:
SubscribeToDataGUI::SubscribeToDataGUI(QWidget* parent) : QDialog(parent) {
widget_.setupUi(this);
IBAdditions::ContractEvent c;
c.symbol = "EUR"; c.currency = "USD"; c.event_ = IBAdditions::TickPrice;
availableTickers_.push_back(c);
model_.reset(new TickerDisplayModel(availableTickers_));
widget_.listView->setModel(model_.get());
widget_.listView->show();
}