2017-03-06 87 views
0

我試圖在QLabel中顯示資源文件中的圖像。所有這些都是從擴展主要核心應用程序的插件發生的。如何在QLabel中顯示圖像

#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); 
} 

該項目編譯沒有任何錯誤,但圖像不顯示。我究竟做錯了什麼?

謝謝大家提前。

項目結構:

**plugins_dir** 
    sampleplugin 
     pluginresources.qrc 
     sample_plugin_resources 
      - Dry-50.png 

回答

2

檢查pix實際上已加載圖像(pix.isNull())。您正在從資源路徑加載圖像,是QRC文件上的完整路徑嗎?

+0

你能解決問題嗎?還有什麼可以嘗試弄清楚的? – cbuchart