×

Discussion Board

Results 1 to 11 of 11

Threaded View

  1. #1
    Nokia Developer Champion
    Join Date
    Nov 2011
    Location
    Tunisia
    Posts
    81

    How to open QML InfoBanner from C++

    Hi,
    Please can someone tell me why when I call a QML function (openInfoBanner) from C++ it doesn't open the InfoBanner?

    this is the code of my test app:

    main.cpp
    Code:
    #include <QtGui/QApplication>
    #include <QtDeclarative>
    #include "qmlapplicationviewer.h"
    #include "myclass.h"
    
    Q_DECL_EXPORT int main(int argc, char *argv[])
    {
        QScopedPointer<QApplication> app(createApplication(argc, argv));
    
        QmlApplicationViewer *viewer = new QmlApplicationViewer();
    
        viewer->setMainQmlFile(QLatin1String("qml/test022/main.qml"));
        viewer->showExpanded();
    
        MyClass myClass;
        myClass.openBanner("Hello Banner");
    
        return app->exec();
    }


    myclass.h
    Code:
    #ifndef MYCLASS_H
    #define MYCLASS_H
    
    #include <Qt>
    #include <QObject>
    #include <QtDeclarative>
    #include <QDeclarativeEngine>
    #include <QDeclarativeContext>
    
    class MyClass : public QObject
    {
        Q_OBJECT
    public:
    
        MyClass(){}
    
        Q_INVOKABLE void openBanner(QVariant txt){
            QDeclarativeEngine *engine = new QDeclarativeEngine;
            QDeclarativeComponent component(engine, QUrl::fromLocalFile("qml/test022/MainPage.qml"));
            if (component.status() == 1){
                QObject *object = component.create();
                QMetaObject::invokeMethod(object, "openInfoBanner", Q_ARG(QVariant, txt));
                object->deleteLater();
            }
            engine->deleteLater();
        }
    };
    
    #endif // MYCLASS_H


    main.qml
    Code:
    import QtQuick 1.1
    import com.nokia.symbian 1.1
    import com.nokia.extras 1.1
    
    PageStackWindow {
        id: window
        initialPage: mainPg
        showStatusBar: true
        showToolBar: true
    
        MainPage {
            id: mainPg
            parent: window
            tools: toolBarLayout
        }
    
        ToolBarLayout {
            id: toolBarLayout
            ToolButton {
                flat: true
                iconSource: "toolbar-back"
                onClicked: window.pageStack.depth <= 1 ? Qt.quit() : window.pageStack.pop()
            }
        }
    }


    MainPage.qml
    Code:
    import QtQuick 1.1
    import com.nokia.symbian 1.1
    import com.nokia.extras 1.1
    
    Page {
        id: mainPage
    
        function openInfoBanner(txt){
            console.log("openInfoBanner(txt) executed") //this log msg is shown correctly
            textCenter.text = txt;
            infBanner.text = txt;
            infBanner.open();
            console.log("infBanner must been opened now!") //this log msg is shown correctly but the infBanner doesn't opened and
            //the textCenter text doesn't changed!
        }
    
        InfoBanner{
            id: infBanner
            timeout: 3000
        }
    
        Text {
            id: textCenter
            anchors.centerIn: parent
            text: qsTr("Hello world!")
            color: platformStyle.colorNormalLight
            font.pixelSize: 20
        }
    }
    Last edited by aymen_ka; 2013-03-24 at 09:17.

Similar Threads

  1. Show "InfoBanner" without QML
    By AlphaX2 in forum Nokia N9
    Replies: 1
    Last Post: 2012-05-31, 08:34
  2. InfoBanner is not working in Qml code
    By Yogesghpatel in forum Nokia N9
    Replies: 6
    Last Post: 2012-05-22, 07:36
  3. QtComponents with MeeGo Harmattan problem - InfoBanner
    By molbal in forum [Archived] Qt Quick
    Replies: 3
    Last Post: 2011-08-02, 19:41
  4. Replies: 4
    Last Post: 2010-03-01, 09:51
  5. Open some specified SMS/MMS message from inbox to open a thrid-party application
    By Mark070508 in forum Symbian Networking & Messaging (Closed)
    Replies: 0
    Last Post: 2009-12-10, 07:46

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •