In-app advertising how to use Inneractive API in QML application
hamishwillee
(Talk | contribs) m (Hamishwillee - Tidy wikitext) |
hamishwillee
(Talk | contribs) m (Hamishwillee - Subedit) |
||
| Line 1: | Line 1: | ||
| − | [[Category:Qt Quick]] | + | [[Category:Qt Quick]][[Category:In-App Advertising]][[Category:Code Examples]] |
| − | {{Abstract|This | + | {{Abstract|This code example shows how you can use the standard {{Icode|QWidget}}-based In-app advertising API widget from within a QML app. The approach given can also be used for displaying other {{Icode|QWidget}} based controls from within QML.}} |
{{ArticleMetaData <!-- v1.1 --> | {{ArticleMetaData <!-- v1.1 --> | ||
| Line 28: | Line 28: | ||
== Introduction == | == Introduction == | ||
| − | Inneractive In-application Advertizing API is Nokia's | + | The Inneractive In-application Advertizing API is the part of Nokia's [http://www.developer.nokia.com/Distribute/Monetizing_your_app/ Monetization Suite]. It allows developers to easily display advertising banners within an application, handling everything from user interaction with the banner through to developer payment. |
| − | + | ||
| − | + | [[File:Fifteenpuzzle_mainscr.JPG|thumb|250px|none|In-application ad servicing solution demo project screen shot]] | |
| + | |||
| + | The API exists provides a click-able ad-banner control box that is derived from {{Icode|QWidget}}. This class can be used within Qt C++ applications directly, but is not immediately compatible with QML applications. This article shows how you can re-use this API within your QML application with minimal implementation efforts. | ||
== Design approach == | == Design approach == | ||
| − | + | The design approach is to create a view container box derived from {{Icode|QDeclarativeItem}} that is available from within QML. The container provides an area where the {{Icode|InnerActiveAdWidget}} can draw itself and also handles re-sizing events from QML document. | |
| − | + | ||
| − | + | ||
== The implementation in three steps== | == The implementation in three steps== | ||
| − | # Create view box container class that will act in QML document as Rectangle element. Please see in AdBannerWidget class declaration below what is important to make it | + | # Create view box container class that will act in QML document as Rectangle element. Please see in {{Icode|AdBannerWidget}} class declaration below what is important to make it interact with QML side. Implementation details can be seen in [http://projects.developer.nokia.com/fifteenpuzzle the project source code] |
#:<code cpp> | #:<code cpp> | ||
class AdBannerWidget : public QDeclarativeItem | class AdBannerWidget : public QDeclarativeItem | ||
{ | { | ||
| − | + | ... | |
private: | private: | ||
//these methods below are to handle events from QML side about the box geometry and painting | //these methods below are to handle events from QML side about the box geometry and painting | ||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); | ||
void geometryChanged(const QRectF & newGeometry, const QRectF & oldGeometry); | void geometryChanged(const QRectF & newGeometry, const QRectF & oldGeometry); | ||
| − | + | ... | |
private: | private: | ||
// data | // data | ||
| Line 56: | Line 56: | ||
}; | }; | ||
</code> | </code> | ||
| − | # Register AdBannerWidget type for QML before document loading --- the most convenient place i think is in Qt application setup -- function main() | + | # Register {{Icode|AdBannerWidget}} type for QML before document loading --- the most convenient place i think is in Qt application setup -- function {{Icode|main()}} |
#: <code cpp>qmlRegisterType<AdBannerWidget>("com.izinin.inneractive.ad", 1, 0, "AdBanner");</code> | #: <code cpp>qmlRegisterType<AdBannerWidget>("com.izinin.inneractive.ad", 1, 0, "AdBanner");</code> | ||
# Use the view box in QML document is shown below | # Use the view box in QML document is shown below | ||
| Line 65: | Line 65: | ||
width: Math.min(screen.width, screen.height) | width: Math.min(screen.width, screen.height) | ||
} | } | ||
| − | + | ... | |
states: [ | states: [ | ||
State { | State { | ||
name: "landscape"; when: screen.width > screen.height | name: "landscape"; when: screen.width > screen.height | ||
| − | + | ... | |
PropertyChanges { | PropertyChanges { | ||
target: adbanner | target: adbanner | ||
| Line 76: | Line 76: | ||
} | } | ||
}, | }, | ||
| − | + | ... | |
</code> | </code> | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
Revision as of 03:50, 23 January 2012
This code example shows how you can use the standard QWidget-based In-app advertising API widget from within a QML app. The approach given can also be used for displaying other QWidget based controls from within QML.
Article Metadata
Code Example
Tested with
Compatibility
Platform Security
Article
Introduction
The Inneractive In-application Advertizing API is the part of Nokia's Monetization Suite. It allows developers to easily display advertising banners within an application, handling everything from user interaction with the banner through to developer payment.
The API exists provides a click-able ad-banner control box that is derived from QWidget. This class can be used within Qt C++ applications directly, but is not immediately compatible with QML applications. This article shows how you can re-use this API within your QML application with minimal implementation efforts.
Design approach
The design approach is to create a view container box derived from QDeclarativeItem that is available from within QML. The container provides an area where the InnerActiveAdWidget can draw itself and also handles re-sizing events from QML document.
The implementation in three steps
- Create view box container class that will act in QML document as Rectangle element. Please see in AdBannerWidget class declaration below what is important to make it interact with QML side. Implementation details can be seen in the project source code
class AdBannerWidget : public QDeclarativeItem
{
...
private:
//these methods below are to handle events from QML side about the box geometry and painting
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
void geometryChanged(const QRectF & newGeometry, const QRectF & oldGeometry);
...
private:
// data
InnerActiveAdModule* ipAdModule; // reference to ad engine
InnerActiveAdWidget* ipAdWidget; // reference to ad widget
};
- Register AdBannerWidget type for QML before document loading --- the most convenient place i think is in Qt application setup -- function main()
-
qmlRegisterType<AdBannerWidget>("com.izinin.inneractive.ad", 1, 0, "AdBanner");
-
- Use the view box in QML document is shown below
AdBanner{
id: adbanner
height: 70
width: Math.min(screen.width, screen.height)
}
...
states: [
State {
name: "landscape"; when: screen.width > screen.height
...
PropertyChanges {
target: adbanner
x:optionbar.x
y:optionbar.y + optionbar.height + screen.margin
}
},
...

