Reputation: 6624
I'm trying to show an image from a resource file in a QLabel. All this is happenning from a plugin that extends the main core application.
#include "sampleplugin.h"
#include <QtWidgets>
SamplePlugin :: SamplePlugin()
{
Q_INIT_RESOURCE(pluginresources);
oLContainerWidget = new QWidget();
olWrapper = new QHBoxLayout();
bagIcon(":/sample_plugin_resources/images/Dry-50.png");
oLContainerWidget -> setLayout(olWrapper);
}
void SamplePlugin :: testIcon(const QString &imageUrl)
{
QPixmap pix(imageUrl);
QLabel *sampleIconLabel = new QLabel();
sampleIconLabel -> setPixmap(pix);
olWrapper -> addWidget(sampleIconLabel);
}
The project compiles without any errors, but the image doesn't show. What am I doing wrong?
Thank you all in advance.
The project structure:
**plugins_dir**
sampleplugin
pluginresources.qrc
sample_plugin_resources
- Dry-50.png
Upvotes: 1
Views: 530
Reputation: 11555
Check that pix
has actually loaded the image (pix.isNull()
). You are loading the image from a resource path, is that the complete path on your QRC file?
Upvotes: 2