当应用程序在后台Symbian中时,在QML中暂停应用程序 [英] Pause application in QML when app is in background Symbian
问题描述
我想知道任何一种纯QML方式来找出应用程序是否在后台,然后相应地停止或播放音乐.在meego中,替代方法是通过PlatformWindow元素,但在Symbian QML中不存在.请帮助
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
推荐答案
最后,我开始使用它了:)并且我通过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()
}
}
}
}
享受:)
这篇关于当应用程序在后台Symbian中时,在QML中暂停应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!