pieview.cpp:5: error: undefined reference to `vtable for PieView'



  • i add a class named PieView to a mainwindow project , build failed with qt5.9.1 , i dont know what's the problem

    #ifndef PIEVIEW_H
    #define PIEVIEW_H
    
    #include <QAbstractItemView>
    #include <QItemSelectionModel>
    #include <QRect>
    #include <QRegion>
    
    class PieView : public QAbstractItemView
    {
        Q_OBJECT
    public:
        PieView(QWidget *parent = 0);
        void paintEvent(QPaintEvent *);
    
        void setSelectionModel(QItemSelectionModel *selectionModel);
        QRegion itemRegion(QModelIndex index);
        QRect visualRect(const QModelIndex &index) const;
        void scrollTo(const QModelIndex &index, ScrollHint hint = EnsureVisible);
    
        QModelIndex indexAt(const QPoint &point) const;
        QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers);
        int horizontalOffset() const;
        int verticalOffset() const;
        bool isIndexHidden(const QModelIndex &index) const;
        void setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command);
    
        QRegion visualRegionForSelection(const QItemSelection &selection) const;
    
    private:
        QItemSelectionModel *selections;
        QList<QRegion> RegionList;
    
    };
    
    #endif // PIEVIEW_H
    
    
    #include "pieview.h"
    #include <QPainter>
    
    
    PieView::PieView(QWidget *parent) : QAbstractItemView(parent)
    {
    
    }
    
    
    
    void PieView::paintEvent(QPaintEvent *)
    {
        QPainter painter(viewport());
        painter.setPen(Qt::black);
    
        int x0 = 40;
        int y0 = 250;
    
        painter.drawLine(x0, y0, 40, 30);
        painter.drawLine(38, 32, 40, 30);
        painter.drawLine(40, 30, 42, 32);
        painter.drawText(20, 30, "sell count");
    
        for(int i = 1; i < 5; i++)
        {
            painter.drawLine(-1, -i*50, 1, -i*50);
            painter.drawText(-20, -i*50, QString("%1").arg(i * 5));
        }
    
        painter.drawLine(x0, y0, 540, 250);
        painter.drawLine(538, 248, 540, 250);
        painter.drawLine(540, 250, 538, 252);
    
        painter.drawText(545, 250, "branch");
    
        int pos = x0 + 20;
        int row;
    
        for(row = 0; row < model()->rowCount(rootIndex()); row++)
        {
    
            QModelIndex index = model()->index(row, 0, rootIndex());
            QString dep = model()->data(index).toString();
    
            painter.drawText(pos, y0 + 20, dep);
            pos += 50;
        }
    
        int posN = x0 + 20;
        for(row = 0; row < model()->rowCount(rootIndex()); row++)
        {
    
            QModelIndex index = model()->index(row, 1, rootIndex());
            int sell = model()->data(index).toDouble();
            int width = 10;
    
            QModelIndex colorIndex = model()->index(row, 0, rootIndex());
            QColor color = QColor(model()->data(colorIndex, Qt::DecorationRole).toString());
    
            if(selections->isSelected(index))
                painter.setBrush(QBrush(color, Qt::Dense3Pattern));
            else
                painter.setBrush(QBrush(color));
    
            painter.drawRect(QRect(posN, y0 - 10 * sell, width, 10*sell));
    
            QRegion regionM(posN, y0 - 10 * sell, width, 10*sell);
    
            RegionList << regionM;
    
            posN += 50;
        }
    
    }
    
    void PieView::setSelectionModel(QItemSelectionModel *selectionModel)
    {
        selections = selectionModel;
    }
    
    
    
    
    QRegion PieView::itemRegion(QModelIndex index)
    {
        QRegion region;
        if(index.column() == 1)
            region = RegionList[index.row()];
    
    
        return region;
    }
    
    
    QModelIndex PieView::indexAt(const QPoint &point) const
    {
        QPoint newPoint(point.x(), point.y());
        QRegion region;
    
        foreach (region, RegionList)
        {
           if(region.contains(newPoint))
           {
               int row = RegionList.indexOf(region);
               QModelIndex index = model()->index(row, 1, rootIndex());
    
               return index;
           }
        }
    
        return QModelIndex();
    }
    
    




  • Sometimes you have to re-run qmake to catch up changes.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.