QtCreator 智能提示功能的bug

在IDE中进行编码的过程中,智能提示功能非常便利,特别是子类化的过程中,虚函数的重写过程。
但是目前在使用QtCreator进行编码的过程中发现,智能提示功能存在bug:
继承一个类A,但是在实现该类的虚函数时,智能提示功能不能提示该类的父类B中包含的虚函数,,除非在继承时也写上其父类B,才能够提示其中的虚函数。
但是存在的问题是,相当于继承了父类,也继承了父类的父类,这样就存在编译不通过的问题。
可以通过帮助文档查找相关的虚函数,copy过来,但是还是智能提示较快捷,如果要实现好几个虚函数的时候还是能够使用智能提示方便。
目前的解决办法是:先继承父类,把父类的父类也写在继承列表,智能提示完成虚函数后,再删除继承列表中父类的父类。

如下示例:
.h文件中代码:
其中QAbstractItemModel就是所谓的"父类的父类":(智能提示将虚函数提示出,写完后,删除即可)

#ifndef STRINGLISTMODEL_H
#define STRINGLISTMODEL_H

#include <QAbstractListModel>
#include <QAbstractItemModel>
#include <QStringList>


class StringListModel : public QAbstractListModel,QAbstractItemModel
{
    Q_OBJECT
public:
    StringListModel(const QStringList &strings, QObject *parent = 0)
        :QAbstractListModel(parent), stringList(strings){}

    int rowCount(const QModelIndex &parent = QModelIndex()) const override;
    QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
    QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;

    Qt::ItemFlags flags(const QModelIndex &index) const override;
    bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;

    bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
    bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;

private:
    QStringList stringList;
};

#endif // STRINGLISTMODEL_H

虚函数写完后,删除父类的父类:

#ifndef STRINGLISTMODEL_H
#define STRINGLISTMODEL_H

#include <QAbstractListModel>
#include <QStringList>


class StringListModel : public QAbstractListModel
{
    Q_OBJECT
public:
    StringListModel(const QStringList &strings, QObject *parent = 0)
        :QAbstractListModel(parent), stringList(strings){}

    int rowCount(const QModelIndex &parent = QModelIndex()) const override;
    QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
    QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;

    Qt::ItemFlags flags(const QModelIndex &index) const override;
    bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;

    bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
    bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;

private:
    QStringList stringList;
};

#endif // STRINGLISTMODEL_H

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值