QQuickImageProvider类错误

时间:2018-07-30 18:39:21

标签: c++ qt qml

我想将QPixmap从C ++迁移到qml。 我用父级QQucikImageProvider创建了一个类

class test : public QQuickImageProvider
{

Q_OBJECT
public:
    test():QQuickImageProvider(QQuickImageProvider::Pixmap)
    {

}
QPixmap requestPixmap(const QString & id, QSize * size, const QSize & requestedSize)
{
    int width = 100;
    int height = 50;

    if (size)
        *size = QSize(width, height);
    QPixmap pixmap(requestedSize.width() > 0 ? requestedSize.width() : width,
                   requestedSize.height() > 0 ? requestedSize.height() : height);
    pixmap.fill(QColor(id).rgba());

    return pixmap;
}

};

并在main.cpp中声明它

int main(int argc, char *argv[])
{
...
VK::test *imgProv = new VK::test();
QQmlApplicationEngine engine;
engine.addImageProvider("myprovider",imgProv);
...
}

但是在编译时,我收到以下错误:

moc_api.cpp:-1: error: undefined reference to `_imp___ZN19QQuickImageProvider11qt_metacastEPKc'

moc_api.cpp:-1: error: undefined reference to `_imp___ZN19QQuickImageProvider11qt_metacallEN11QMetaObject4CallEiPPv'

moc_api.cpp:-1: error: undefined reference to `_imp___ZN19QQuickImageProvider16staticMetaObjectE'

0 个答案:

没有答案