Error when inherit from QQuickGridView



  • I want to override the function of keyPreesEvent of QQuickGridView, so I created an class inherit from QQuickGridView, but the link failed.
    Anybody who can help?

    #ifndef BASEGRIDVIEW_P_H
    #define BASEGRIDVIEW_P_H

    #include <QObject>
    #include <QtQuick/private/qquickgridview_p.h>

    class BaseGridView : public QQuickGridView
    {
    Q_OBJECT
    // Q_INTERFACES(QQmlParserStatus)

    public:
    explicit BaseGridView(QQuickItem * parent = Q_NULLPTR): QQuickGridView(parent)
    {

    }
    

    //protected:
    // void keyPressEvent(QKeyEvent *) Q_DECL_OVERRIDE;

    // Q_DISABLE_COPY(BaseGridView)
    };

    #endif // BASEGRIDVIEW_P_H

    I got these link errors:

    ./debug/moc_basegridview_p.cpp:79: undefined reference to QQuickGridView::qt_metacast(char const*)' ./debug/moc_basegridview_p.cpp:84: undefined reference toQQuickGridView::qt_metacall(QMetaObject::Call, int, void**)'
    ./debug\moc_basegridview_p.o:moc_basegridview_p.cpp:(.rdata+0x4): undefined reference to QQuickGridView::staticMetaObject' ./debug\moc_basegridview_p.o:moc_basegridview_p.cpp:(.rdata$_ZTV12BaseGridView[__ZTV12BaseGridView]+0x5c): undefined reference toQQuickGridView::keyPressEvent(QKeyEvent*)'
    ./debug\moc_basegridview_p.o:moc_basegridview_p.cpp:(.rdata$_ZTV12BaseGridView[__ZTV12BaseGridView]+0xb4): undefined reference to QQuickGridView::geometryChanged(QRectF const&, QRectF const&)' ./debug\moc_basegridview_p.o:moc_basegridview_p.cpp:(.rdata$_ZTV12BaseGridView[__ZTV12BaseGridView]+0xe4): undefined reference toQQuickGridView::viewportMoved(QFlagsQt::Orientation)'
    ./debug\moc_basegridview_p.o:moc_basegridview_p.cpp:(.rdata$_ZTV12BaseGridView[__ZTV12BaseGridView]+0xe8): undefined reference to QQuickGridView::setHighlightFollowsCurrentItem(bool)' ./debug\moc_basegridview_p.o:moc_basegridview_p.cpp:(.rdata$_ZTV12BaseGridView[__ZTV12BaseGridView]+0xec): undefined reference toQQuickGridView::setHighlightMoveDuration(int)'
    ./debug\moc_basegridview_p.o:moc_basegridview_p.cpp:(.rdata$_ZTV12BaseGridView[__ZTV12BaseGridView]+0xf0): undefined reference to QQuickGridView::initItem(int, QObject*)' /plugin/basegridview_p.h:9: undefined reference toQQuickGridView::~QQuickGridView()'

    In my pro file, I already added this:
    QT += core qml quick
    QT += core-private gui-private qml-private quick-private

    BTW, when I inherit from QQuickFlickable, there is no link error.

    I'm using Qt5.6.0


  • Moderators

    @zeangel I'm not aware of the error( may be you are missing some header files ?) but why would you want to subclass private classes ? Chances are that the code changes with each new releases.
    I think you should have a look at Keys QML Type.


Log in to reply
 

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