2,C++实现接口
接口声明:Q_INVOKABLE unsigend int getFistIndex(QString ch);
接口实现:
unsigend int mainWindow::getFistIndex(QString ch)
{
qDebug() <<“seach fist char = ” << ch;
return (m_contactListModel->getSearchResult(ch) - 1);
}
3, getSearchResult实现
(1)getSearchResult所在头文件
/*********************************************
文 件 名:phonebooklistitem.h
描 述 : 电话簿列表
*********************************************/
class PhonebookListItem
{
public:
PhonebookListItem(const QString &ID, const QString &name, const QString &number, const QString &type, const QString &nameSZM, const QString &nameGroup);
QString ID() const;
QString name() const;
QString number() const;
QString type() const;
QString nameSZM() const;
QString nameGroup() const;
private:
QString m_ID;
QString m_name;
QString m_number;
QString m_type;
QString m_nameSZM;
QString m_nameGroup;
};
class PhonebookListModel : public QAbstractListModel
{
Q_OBJECT
public:
explicit PhonebookListModel(QObject *parent = 0);
enum PhonebookListItemRoles{
IDRole = Qt::UserRole + 1,
NameRole,
NumberRole,
TypeRole,
NameSZMRole,
NameGroupRole,
IconRole
};
//getSearchResult声明
unsigned int getSearchResult(QString ch);
void addContactItem(const PhonebookListItem &contactItem);
void clear();
int rowCount(const QModelIndex & parent = QModelIndex()) const;
QVariant data(const QModelIndex & index, int role = Qt::UserRole) const;
private:
QList m_contactItems;
protected:
QHash