Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ QQuickImageProvider类错误_C++_Qt_Qml - Fatal编程技术网

C++ QQuickImageProvider类错误

C++ QQuickImageProvider类错误,c++,qt,qml,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 QS

我想将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'

试着删除Mohammad Kanan的一个可能的复制品,它没有帮助