10-12-2012 11:26 AM
I have placed an png image in the main folder of my project (same as icon) and I am using..
QIcon *qq = new QIcon("app/native/testimage.png");
but the QIcon is reported as null.
What am I doing wrong please?
10-12-2012 12:32 PM - edited 10-12-2012 12:34 PM
try this QDir::currentPath()
then set your image path relative to that.
some more info:
10-12-2012 12:50 PM
I have just tried
QIcon *qq = new QIcon(QDir::currentPath()+"/pcicon.png");
but still I cant see the image in my list and my list delegate reports that it is null after casting in its paint function..
QIcon ic = QIcon(qvariant_cast<QPixmap>(index.data(Qt:ecorationRole)));
//ic is null after this.
I have watched 3 hours passed by trying to put an image in a list - is qt really this difficult?
10-12-2012 04:06 PM - edited 10-12-2012 04:13 PM
Consider using the QResource system for all your embedded images and resources. No need to worry about asset paths and such then.
Then you just access with the path like this: "qrc:/prefix/image.png"
10-12-2012 04:54 PM
Thank you all for your replies,
it turned out it was the way I was casting the image data in the list delegate, I should have cast to QVariant and then to QIcon, still learning!