×
Namespaces

Variants
Actions
(Difference between revisions)

Using resources in Qt

From Nokia Developer Wiki
Jump to: navigation, search
taaidant (Talk | contribs)
hamishwillee (Talk | contribs)
m (Text replace - "<code cpp>" to "<code cpp-qt>")
 
(12 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{CodeSnippet
+
[[Category:Qt]][[Category:Code Snippet]][[Category:Code Snippet]]
|id=
+
{{ArticleMetaData <!-- v1.2 -->
|platform=Qt
+
|sourcecode= <!-- Link to example source code (e.g. [[Media:The Code Example ZIP.zip]]) -->
|devices=N97
+
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
|category=Qt
+
|devices= Nokia N97
|subcategory=Files/Data
+
|sdk= Qt 4.5 Garden Pre-release
|creationdate=September 9, 2009
+
|platform= Qt
|keywords=Qt, resources
+
|devicecompatability= <!-- Compatible devices (e.g.: All* (must have GPS) ) -->
 +
|dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 -->
 +
|signing= <!-- Empty or one of Self-Signed, DevCert, Manufacturer -->
 +
|capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. -->
 +
|keywords= Qt, resources
 +
|language= <!-- Language category code for non-English topics - e.g. Lang-Chinese -->
 +
|translated-by= <!-- [[User:XXXX]] -->
 +
|translated-from-title= <!-- Title only -->
 +
|translated-from-id= <!-- Id of translated revision -->
 +
|review-by= <!-- After re-review: [[User:username]] -->
 +
|review-timestamp= <!-- After re-review: YYYYMMDD -->
 +
|update-by= <!-- After significant update: [[User:username]]-->
 +
|update-timestamp= <!-- After significant update: YYYYMMDD -->
 +
|creationdate= 20091124
 +
|author= [[User:Taaidant]]
 +
<!-- The following are not in current metadata -->
 +
|subcategory= Files/Data
 +
|id= CS001503
 
}}
 
}}
  
Line 15: Line 32:
 
==Preconditions==
 
==Preconditions==
  
* Qt is installed on your platform
+
None
** S60
+
*** 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]]
+
*** Check this link for installation guide: [http://pepper.troll.no/s60prereleases/doc/install-s60.html How to install the package].
+
** Maemo
+
*** More information about Qt on Maemo can be found here: [http://qt4.garage.maemo.org/ Qt4 Maemo port]
+
  
 
== Using resources in Qt ==
 
== Using resources in Qt ==
Line 27: Line 38:
 
=== QRE.pro ===
 
=== QRE.pro ===
  
Adding resource file to project file.
+
Add a resource file to a project file:
  
<code>
+
<code text>
 
#  Copyright (c) 2009 Nokia Corporation
 
#  Copyright (c) 2009 Nokia Corporation
 
TEMPLATE = app
 
TEMPLATE = app
Line 42: Line 53:
 
=== qre.qrc ===
 
=== qre.qrc ===
  
Adding resources to resource file.
+
Add resources to a resource file:
  
<code>
+
<code text>
 
<!-- Copyright (c) 2009 Nokia Corporation  -->
 
<!-- Copyright (c) 2009 Nokia Corporation  -->
 
<RCC>
 
<RCC>
Line 55: Line 66:
 
=== qt-logo.png ===
 
=== qt-logo.png ===
  
[[Image:qt-logo.png]]
+
[[File:qt-logo.png]]
  
 
=== main.cpp ===
 
=== main.cpp ===
  
Referencing resources from the code.
+
Reference resources from the code:
  
<code cpp>
+
<code cpp-qt>
 
/*
 
/*
 
  * Copyright (c) 2009 Nokia Corporation
 
  * Copyright (c) 2009 Nokia Corporation
Line 103: Line 114:
 
Now you know how to add and reference resources in Qt.
 
Now you know how to add and reference resources in Qt.
  
[[Image:QRE.png]]
+
[[File:QRE.png]]
  
 
==See also==
 
==See also==
  
* [http://doc.trolltech.com/resources.html The Qt Resource System]
+
* [http://doc.trolltech.com/4.7/resources.html The Qt Resource System][[Category:MeeGo Harmattan]] [[Category:Symbian]]
 
+
[[Category:Qt]][[Category:Code Examples]]
+

Latest revision as of 04:18, 11 October 2012

Article Metadata
Tested with
SDK: Qt 4.5 Garden Pre-release
Devices(s): Nokia N97
Compatibility
Platform(s): Qt
Symbian
Article
Keywords: Qt, resources
Created: taaidant (24 Nov 2009)
Last edited: hamishwillee (11 Oct 2012)

Contents

[edit] Overview

This snippet shows how to add and reference resources in Qt.

[edit] Preconditions

None

[edit] Using resources in Qt

[edit] 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

[edit] qre.qrc

Add resources to a resource file:

<!-- Copyright (c) 2009 Nokia Corporation  -->
<RCC>
<qresource prefix="/" >
<file>qt-logo.png</file>
</qresource>
</RCC>

[edit] qt-logo.png

Qt-logo.png

[edit] 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;
}

[edit] Postconditions

Now you know how to add and reference resources in Qt.

QRE.png

[edit] See also

This page was last modified on 11 October 2012, at 04:18.
210 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×