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>
    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"
        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 baners is showed we can to reposition it
        onStartAdBannerShowed: {
            startAdBannerPosition = Qt.point(0,
                                     (appWindow.height - adCtl.startAdBannerHeight * 1.3))
        //when AdMob baners is showed we can to reposition it
        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: {

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.