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();
}
You’ve fallen foul of what’s known as C++’s ‘most vexing parse’. Specifically, this:
declares a function called
itemthat takes a single parameter of typeQPixmapand 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
addItemwith an argument of typeQGraphicsPixmapItem (&)(QPixmap)– that is, reference to a function taking aQPixmapand returning aQGraphicsPixmapItem(which is the type of the expressionitem).