Discussion Board

Results 1 to 8 of 8
  1. #1
    Nokia Developer Champion aymen_ka's Avatar
    Join Date
    Nov 2011
    Location
    Tunisia
    Posts
    65
    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.

  2. #2
    Nokia Developer Champion vineet.jain's Avatar
    Join Date
    Jun 2008
    Location
    Noida,India
    Posts
    3,861
    Does a log gets created at the beginning of the function openInfoBanner(txt)?

  3. #3
    Nokia Developer Champion aymen_ka's Avatar
    Join Date
    Nov 2011
    Location
    Tunisia
    Posts
    65
    Quote Originally Posted by vineet.jain View Post
    Does a log gets created at the beginning of the function openInfoBanner(txt)?
    Yes, it show both log "openInfoBanner(txt) executed" and "infBanner must been opened now!" but doesn't open the InfoBanner!
    If I call the function openInfoBanner(txt) from QML it open the banner without problem, but when I call the function from C++ it doesn't open the banner!

  4. #4
    Nokia Developer Champion vineet.jain's Avatar
    Join Date
    Jun 2008
    Location
    Noida,India
    Posts
    3,861
    Just for the test purpose, try implementing something else in that function, let say change the text of a button & see if it works. This way you may know that problem is there in calling the method from c++ or the infobanner.Open() works like that only.

  5. #5
    Nokia Developer Champion aymen_ka's Avatar
    Join Date
    Nov 2011
    Location
    Tunisia
    Posts
    65
    Quote Originally Posted by vineet.jain View Post
    Just for the test purpose, try implementing something else in that function, let say change the text of a button & see if it works. This way you may know that problem is there in calling the method from c++ or the infobanner.Open() works like that only.
    Tried that and it doesn't change the text too! it only show logs. Any idea to resolve this problem?

  6. #6
    Nokia Developer Champion vineet.jain's Avatar
    Join Date
    Jun 2008
    Location
    Noida,India
    Posts
    3,861
    what does QMetaObject::invokeMethod returns? is it true or false?

  7. #7
    Nokia Developer Champion aymen_ka's Avatar
    Join Date
    Nov 2011
    Location
    Tunisia
    Posts
    65
    Quote Originally Posted by vineet.jain View Post
    what does QMetaObject::invokeMethod returns? is it true or false?
    it return true

  8. #8
    Nokia Developer Champion aymen_ka's Avatar
    Join Date
    Nov 2011
    Location
    Tunisia
    Posts
    65
    Any idea how to resolve this issue?

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
  •  
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved