Howto QML and Qt Quick

Gilmanov Ildar edited this page Dec 25, 2015 · 6 revisions

Add to main.cpp

    #include <mobile/adctl/adctl.h>
    #include <QApplication>
    
    ...
    
    //AdCtl
    QApplication::setApplicationName("Darkstories");
    QApplication::setApplicationVersion("1.1");
    qmlRegisterType<AdCtl>("ru.forsk.adctl", 1, 0, "AdCtl");

Add to main.qml

    import ru.forsk.adctl 1.0

    ...

    AdCtl {
        id: adCtl
    
        //manage enabled components
        adMobBannerEnabled: true
        adMobIinterstitialEnabled: true
        startAdBannerEnabled: true
        gAnalyticsEnabled: true
    
        //set ids
        //for test purposes: "ca-app-pub-3940256099942544/6300978111"
        bannerAdMobId: "YOUR_BANNER_ADMOB_UNIT_ID"
        //for test purposes: "ca-app-pub-3940256099942544/1033173712"
        interstitialAdMobId: "YOUR_INTERSTITIAL_ADMOB_UNIT_ID"
        startAdId: "YOUR_STARTADMOBI_ID"
        gAnalyticsId: "YOUR_GANALYTICS_TRACKING_ID"
        //see https://developers.google.com/admob/android/targeting
        testDevices: "YOUR_TEST_DEVICE_ID"
    
        //Start positions for banners.
        adMobBannerPosition: Qt.point(0,-500)
        startAdBannerPosition: Qt.point(0,-500)
        startAdBannerSize: Qt.size(250, 50)
    
        //when StartAd.mobi baners is showed we can to reposition it
        onStartAdBannerShowed: {
            console.log("onStartAdBannerShowed");
            startAdBannerPosition = Qt.point(0,
                                     (appWindow.height - adCtl.startAdBannerHeight * 1.3))
        }
    
        //when AdMob baners is showed we can to reposition it
        onAdMobBannerShowed: {
            console.log("onAdMobBannerShowed");
            adMobBannerPosition = Qt.point((appWindow.width - adCtl.adMobBannerWidth) * 0.5,
                                     (appWindow.height - adCtl.adMobBannerHeight * 1.5 - 200))
        }
    
        //When all variables are setted, we can to initialize our code
        Component.onCompleted: {
            adCtl.init();
            adCtl.signInGPGS();
        }
    }

Example, interact with AdCtl

    Rectangle {
        id: root
    
        anchors.fill: parent
        anchors.bottomMargin: adCtl.startAdBannerHeight
        Component.onCompleted: { adCtl.sendGaAppView("MainWindow"); }
    }
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.