×
Namespaces

Variants
Actions
(Difference between revisions)

In-app advertising how to use Inneractive API in QML application

From Nokia Developer Wiki
Jump to: navigation, search
hamishwillee (Talk | contribs)
m (Hamishwillee - Addition to article of: Category:MeeGo Category:Symbian. (Add platform categories))
hamishwillee (Talk | contribs)
m (Text replace - "<code cpp>" to "<code cpp-qt>")
(One intermediate revision by one user not shown)
Line 41: Line 41:
  
 
# Create a view box container class to define the rectangular area in QML in which the banner is displayed (this is the minimal implementation of a visual QML element). The {{Icode|AdBannerWidget}} class declaration below shows the important code for making the element interact with QML. Implementation details can be seen in [http://projects.developer.nokia.com/fifteenpuzzle the project source code]
 
# Create a view box container class to define the rectangular area in QML in which the banner is displayed (this is the minimal implementation of a visual QML element). The {{Icode|AdBannerWidget}} class declaration below shows the important code for making the element interact with QML. Implementation details can be seen in [http://projects.developer.nokia.com/fifteenpuzzle the project source code]
#:<code cpp>
+
#:<code cpp-qt>
 
     class AdBannerWidget : public QDeclarativeItem
 
     class AdBannerWidget : public QDeclarativeItem
 
     {  
 
     {  
Line 57: Line 57:
 
</code>
 
</code>
 
# Register {{Icode|AdBannerWidget}} type for QML before document loading --- the most convenient place i think is in Qt application setup -- function {{Icode|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-qt>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
#:<code cpp>
+
#:<code cpp-qt>
 
     AdBanner{
 
     AdBanner{
 
         id: adbanner
 
         id: adbanner
Line 77: Line 77:
 
         },
 
         },
 
...
 
...
</code>[[Category:MeeGo]] [[Category:Symbian]]
+
</code>[[Category:MeeGo Harmattan]] [[Category:Symbian]]

Revision as of 04:20, 11 October 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
Source file: fifteen puzzle game
Tested with
Devices(s): N8
Compatibility
Platform(s): Symbian^3, Anna, Belle
Symbian
Platform Security
Signing Required: DevCert
Capabilities: NetworkServices LocalServices ReadUserData WriteUserData UserEnvironment ReadDeviceData
Article
Keywords: In-application Analytic Ad Inneractive API
Created: izinin (19 Jan 2012)
Last edited: hamishwillee (11 Oct 2012)

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.

In-application ad servicing solution demo project screen shot

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

  1. Create a view box container class to define the rectangular area in QML in which the banner is displayed (this is the minimal implementation of a visual QML element). The AdBannerWidget class declaration below shows the important code for making the element interact with QML. 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
    };
  2. 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");
  3. 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
    }
    },
    ...
103 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.

×