且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

当应用程序在后台Symbian中时,在QML中暂停应用程序

更新时间:2022-12-27 10:47:27

最后,我开始使用它了:)并且我通过Qt的方式实现了...这是步骤

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

1)创建一个类MyEventFilter

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)然后在main.cpp中包含此文件,包括该类并像这样添加setContext属性

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

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

3)在qml文件中这样称呼它:

3) in qml file call it like this:

 Item {
    id: name
    Connections
    {
        target:myqmlobject
        onQmlvisiblechange:
        {


            if(is_foreground)
            {
              //dont do anything...
            }
            else
            {


                playSound.stop()
            }
        }
    }
}

享受:)