c++ - QQuickImageProvider 类错误
问题描述
我想将 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'
解决方案
推荐阅读
- amazon-web-services - EC2 实例在附加卷后启动和停止
- c# - 使用依赖属性 WPF 按钮绑定字符串而不是 ImageSource
- c++ - 在 C++ 中具有键值对:
作为关键 作为价值 - javascript - 如何为 AWS mp4 目标链接创建下载链接
- excel - Excel 自动递增设置值并重置为初始值
- python - 如何以 d/m/y 格式从 python 中的 csv 导入日期列
- javascript - 使用 Laravel 运行的 Javascript 中出现意外的标识符
- php - 如何更新 WordPress wp_usermeta?
- erlang - 函数名与内核模块中的函数冲突。有没有办法先调用自己的函数?
- r - 具有零膨胀数据的混合效应模型 - 使用“pscl”包中的 zeroinfl() 的错误消息