传递对 QPixmap ctor 的引用
当我尝试传递似乎是对我的 QPixmap
的引用时,我收到错误:
error: no matching function for call to ‘QGraphicsScene::addItem(QGraphicsPixmapItem (&)(QPixmap))’
问题是我不知道该引用来自哪里,尽管我猜测它来自来自迭代器。
void MainWindow::addItems(std::map<std::string, QString> * items)
{
std::map<std::string, QString>::const_iterator current;
for(current = items->begin(); current != items->end(); ++current)
{
QString cur = current->second;
QGraphicsPixmapItem item(QPixmap(cur));
_scene->addItem(item);
}
}
如果是这种情况,有没有办法取消引用迭代器?不然的话,我到底做错了什么?
调用它的代码
int main(int argc, char *argv[])
{
std::map<std::string, QString> * items;
items->insert(std::pair<std::string, QString>("ozone", ":/images/ozone_sprite.png"));
QApplication a(argc, argv);
MainWindow window;
window.addItems(items);
window.show();
delete items;
return a.exec();
}
When I try to pass what appears to be a reference to my QPixmap
, I get an error:
error: no matching function for call to ‘QGraphicsScene::addItem(QGraphicsPixmapItem (&)(QPixmap))’
The problem is that I don't know where this reference is coming from, though I'm guessing it's coming from the iterator.
void MainWindow::addItems(std::map<std::string, QString> * items)
{
std::map<std::string, QString>::const_iterator current;
for(current = items->begin(); current != items->end(); ++current)
{
QString cur = current->second;
QGraphicsPixmapItem item(QPixmap(cur));
_scene->addItem(item);
}
}
If that's the case, is there a way to de-reference the iterator
? Otherwise, what is it that I'm doing wrong?
The code which calls it
int main(int argc, char *argv[])
{
std::map<std::string, QString> * items;
items->insert(std::pair<std::string, QString>("ozone", ":/images/ozone_sprite.png"));
QApplication a(argc, argv);
MainWindow window;
window.addItems(items);
window.show();
delete items;
return a.exec();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您已经犯了所谓的 C++ 的“最令人烦恼的解析”。具体来说,它:
声明一个名为
item
的函数,该函数采用QPixmap
类型的单个参数并返回一个QGraphicsPixmapItem
。要解决此问题,请写入:请参阅此处:
http://en.wikipedia.org/wiki/Most_veshing_parse
就错误而言,请注意您正在尝试使用
QGraphicsPixmapItem (&)(QPixmap)
类型的参数调用addItem
- 也就是说,引用一个采用QPixmap
并返回QGraphicsPixmapItem
的函数(这是表达式item
的类型)。You've fallen foul of what's known as C++'s 'most vexing parse'. Specifically, this:
declares a function called
item
that takes a single parameter of typeQPixmap
and returns aQGraphicsPixmapItem
. To fix this, write:See here:
http://en.wikipedia.org/wiki/Most_vexing_parse
As far as the error goes, note that you're trying to call
addItem
with an argument of typeQGraphicsPixmapItem (&)(QPixmap)
- that is, reference to a function taking aQPixmap
and returning aQGraphicsPixmapItem
(which is the type of the expressionitem
).