Search code examples
qtvisual-studio-201364-bitqpixmapqlabel

Image not shown using Qpixmap with QT5.4 and mvs2013 x64


I am using QT (version 5.4 msvc2013_64) with of-course vs2013. The compilation is successful but when running not every thing functions. Before with vs2010 and QT (i think version 5.1 msvc_2010_opengl do not remember exactly) every thing was working but now things are wried which maybe typical with the start of newer versions but need to be resolved. I also got other issues with this but lets get this resolved first as maybe others will be resolved too else I will post another question for the other problems. Of-course If i do not see a solution to this problem with the current QT and vs I will switch to vs2012 (requires downloading and installing); Maybe then everything will work as before. Thanks in advance.

ui_ta7feezquran.h

/********************************************************************************
    ** Form generated from reading UI file 'ta7feezquran.ui'
    **
    ** Created by: Qt User Interface Compiler version 5.4.1
    **
    ** WARNING! All changes made in this file will be lost when recompiling UI file!
    ********************************************************************************/

#ifndef UI_TA7FEEZQURAN_H
#define UI_TA7FEEZQURAN_H

#include <QtCore/QVariant>
#include <QtWidgets/QAction>
#include <QtWidgets/QApplication>
#include <QtWidgets/QButtonGroup>
#include <QtWidgets/QHeaderView>
#include <QtWidgets/QLabel>
#include <QtWidgets/QMainWindow>
#include <QtWidgets/QMenuBar>
#include <QtWidgets/QToolBar>
#include <QtWidgets/QWidget>

QT_BEGIN_NAMESPACE

class Ui_Ta7feezQuranClass
{
public:
    QWidget *centralWidget;
    QLabel *a;
    QMenuBar *menuBar;
    QToolBar *mainToolBar;

    void setupUi(QMainWindow *Ta7feezQuranClass)
    {
        if (Ta7feezQuranClass->objectName().isEmpty())
            Ta7feezQuranClass->setObjectName(QStringLiteral("Ta7feezQuranClass"));
        Ta7feezQuranClass->resize(572, 485);
        centralWidget = new QWidget(Ta7feezQuranClass);
        centralWidget->setObjectName(QStringLiteral("centralWidget"));
        a = new QLabel(centralWidget);
        a->setObjectName(QStringLiteral("a"));
        a->setGeometry(QRect(-30, -20, 601, 471));
        a->setPixmap(QPixmap(QString::fromUtf8(":/Ta7feezQuran/Resources/Amasjed Alharam.jpg")));
        a->setScaledContents(true);
        Ta7feezQuranClass->setCentralWidget(centralWidget);
        menuBar = new QMenuBar(Ta7feezQuranClass);
        menuBar->setObjectName(QStringLiteral("menuBar"));
        menuBar->setGeometry(QRect(0, 0, 572, 21));
        menuBar->setLayoutDirection(Qt::RightToLeft);
        Ta7feezQuranClass->setMenuBar(menuBar);
        mainToolBar = new QToolBar(Ta7feezQuranClass);
        mainToolBar->setObjectName(QStringLiteral("mainToolBar"));
        Ta7feezQuranClass->addToolBar(Qt::TopToolBarArea, mainToolBar);

        retranslateUi(Ta7feezQuranClass);

        QMetaObject::connectSlotsByName(Ta7feezQuranClass);
    } // setupUi

    void retranslateUi(QMainWindow *Ta7feezQuranClass)
    {
        Ta7feezQuranClass->setWindowTitle(QApplication::translate("Ta7feezQuranClass", "Ta7feezQuran", 0));
        a->setText(QString());
    } // retranslateUi

};

namespace Ui {
    class Ta7feezQuranClass: public Ui_Ta7feezQuranClass {};
} // namespace Ui

QT_END_NAMESPACE

#endif // UI_TA7FEEZQURAN_H

ta7feezquran.h

#ifndef TA7FEEZQURAN_H
#define TA7FEEZQURAN_H

#include <QtWidgets/QMainWindow>
#include "ui_ta7feezquran.h"

class Ta7feezQuran : public QMainWindow
{
    Q_OBJECT

public:
    Ta7feezQuran(QWidget *parent = 0);
    ~Ta7feezQuran();

private:
    Ui::Ta7feezQuranClass ui;
};

#endif // TA7FEEZQURAN_H

ta7feezquran.cpp

#include "ta7feezquran.h"

Ta7feezQuran::Ta7feezQuran(QWidget *parent)
    : QMainWindow(parent)
{
    ui.setupUi(this);
}

Ta7feezQuran::~Ta7feezQuran()
{

}

main.cpp

#include "ta7feezquran.h"
#include <QtWidgets/QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    Ta7feezQuran w;
    w.show();
    return a.exec();
}

ta7feezquran.qrc

<RCC>
    <qresource prefix="/Ta7feezQuran">
        <file>Resources/Amasjed Alharam.jpg</file>
    </qresource>
</RCC>

Solution

  • Some Application features used, for example images, multimedia, print support, etc., require the use of qt plugins.

    The required plugins should be copied to the executable folder (folder where .exe file is included) by copying the plugin folders (with the dlls included) and pasting them inside the executable folder. Every thing else should work as expected.

    In this case imageformats folder (with qjpeg.dll included as the file used is jpg) is needed to copied.