Search code examples
backgroundsymbianqml

Pause application in QML when app is in background Symbian


I want to know of any pure QML way to find out whether the application is in the background or not and then accordingly stop or play music. In meego the alternate way to do is through the PlatformWindow Element but it does not exist in Symbian QML. Help needed please


Solution

  • Finally I got it working :) and i did it though Qt way... here are the steps

    1) Create a class MyEventFilter

    class myEventFilter : public QObject
    {
    
    bool eventFilter(QObject *obj, QEvent *event) {
        switch(event->type()) {
        case QEvent::WindowActivate:
            emit qmlvisiblechange(true);
            qDebug() << "Window activated";
    
            bis_foreground=true;
            return true;
        case QEvent::WindowDeactivate:
            emit qmlvisiblechange(false);
            qDebug() << "Window deactivated";
    
            bis_foreground=false;
            return true;
        default:
        return false;
        }
    }
    
    
     void dosomething();
    
    private:
       int something;
    public:
       bool bis_foreground;
          Q_OBJECT
     public slots:
       Q_INVOKABLE QString checkvisibility() {
           if (bis_foreground==true) return "true";
           else return "false";
       }
    signals:
        void qmlvisiblechange(bool is_foreground);
    
    }; 
    

    2) Then in main.cpp include this file include the class and add setContext propery like this

    context->setContextProperty("myqmlobject", &ef);
    

    3) in qml file call it like this:

     Item {
        id: name
        Connections
        {
            target:myqmlobject
            onQmlvisiblechange:
            {
    
    
                if(is_foreground)
                {
                  //dont do anything...
                }
                else
                {
    
    
                    playSound.stop()
                }
            }
        }
    }
    

    Enjoy :)