Using resources in Qt
copyeditor
(Talk | contribs) m |
|||
| Line 1: | Line 1: | ||
| + | {{KBCS}} | ||
{{CodeSnippet | {{CodeSnippet | ||
| − | |id= | + | |id=CS001503 |
|platform=Qt | |platform=Qt | ||
| − | |devices=N97 | + | |devices=Nokia N97 |
|category=Qt | |category=Qt | ||
|subcategory=Files/Data | |subcategory=Files/Data | ||
| − | |creationdate= | + | |creationdate=November 24, 2009 |
|keywords=Qt, resources | |keywords=Qt, resources | ||
}} | }} | ||
| Line 15: | Line 16: | ||
==Preconditions== | ==Preconditions== | ||
| − | * Qt is installed on your platform | + | * Qt is installed on your platform. |
| − | ** S60 | + | ** S60: |
*** Download Qt for S60 release from here: [http://pepper.troll.no/s60prereleases/ Qt for S60 pre-release] | *** Download Qt for S60 release from here: [http://pepper.troll.no/s60prereleases/ Qt for S60 pre-release] | ||
*** Install Qt for S60: [[Installing Qt on S60]] | *** Install Qt for S60: [[Installing Qt on S60]] | ||
| − | *** Check this link for installation guide: [http://pepper.troll.no/s60prereleases/doc/install-s60.html How to install the package] | + | *** Check this link for installation guide: [http://pepper.troll.no/s60prereleases/doc/install-s60.html How to install the package] |
| − | ** Maemo | + | ** Maemo: |
*** More information about Qt on Maemo can be found here: [http://qt4.garage.maemo.org/ Qt4 Maemo port] | *** More information about Qt on Maemo can be found here: [http://qt4.garage.maemo.org/ Qt4 Maemo port] | ||
| Line 27: | Line 28: | ||
=== QRE.pro === | === QRE.pro === | ||
| − | + | Add a resource file to a project file: | |
<code> | <code> | ||
| Line 42: | Line 43: | ||
=== qre.qrc === | === qre.qrc === | ||
| − | + | Add resources to a resource file: | |
<code> | <code> | ||
| Line 59: | Line 60: | ||
=== main.cpp === | === main.cpp === | ||
| − | + | Reference resources from the code: | |
<code cpp> | <code cpp> | ||
Revision as of 16:41, 24 November 2009
Article Metadata
Tested with
Devices(s): Nokia N97
Compatibility
Platform(s): Qt
Article
Keywords: Qt, resources
Created: (24 Nov 2009)
Last edited: copyeditor
(24 Nov 2009)
Contents |
Overview
This snippet shows how to add and reference resources in Qt.
Preconditions
- Qt is installed on your platform.
- S60:
- Download Qt for S60 release from here: Qt for S60 pre-release
- Install Qt for S60: Installing Qt on S60
- Check this link for installation guide: How to install the package
- Maemo:
- More information about Qt on Maemo can be found here: Qt4 Maemo port
- S60:
Using resources in Qt
QRE.pro
Add a resource file to a project file:
# Copyright (c) 2009 Nokia Corporation
TEMPLATE = app
TARGET = QRE
QT += core \
gui
SOURCES += main.cpp
# This is how the qre.qrc is added to the project.
RESOURCES += qre.qrc
qre.qrc
Add resources to a resource file:
<!-- Copyright (c) 2009 Nokia Corporation -->
<RCC>
<qresource prefix="/" >
<file>qt-logo.png</file>
</qresource>
</RCC>
qt-logo.png
main.cpp
Reference resources from the code:
/*
* Copyright (c) 2009 Nokia Corporation
*/
#include <QtGui>
#include <QApplication>
int main(int argc, char *argv[]) {
QApplication a(argc, argv);
/* QMainWindow as our window */
QMainWindow* w = new QMainWindow;
/* QFrame as our centralWidget */
QFrame* centralW = new QFrame(w);
w->setCentralWidget(centralW);
/* QVBoxLayout as our central widgets layout */
QVBoxLayout* layout = new QVBoxLayout(centralW);
centralW->setLayout(layout);
/* QLabel is used as our logo container. */
QLabel* qtLogoContainer = new QLabel;
/* QPixmap is used to load the image from resources
* defined in qre.qrc file. */
qtLogoContainer->setPixmap(QPixmap(":/qt-logo.png"));
/* To get the logo shown we need to add the container containing
* the logo to the layout. */
layout->addWidget(qtLogoContainer);
/* We'll display the window maximized. */
w->showMaximized();
/* Run till the execution ends. */
int returnValue = a.exec();
/* Flag the window to be deleted.*/
w->deleteLater();
/* Return the execution return value.*/
return returnValue;
}
Postconditions
Now you know how to add and reference resources in Qt.


