アプリケーションがバックグラウンドにあるかどうかを確認し、それに応じて音楽を停止または再生するための純粋なQMLの方法を知りたいです。meegoでは、PlatformWindow Elementを使用する別の方法がありますが、SymbianQMLには存在しません。助けが必要です
2 に答える
最後に私はそれを動作させました:)そして私はQtの方法でそれをしました...ここにステップがあります
1)クラス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を適切に追加します。
context->setContextProperty("myqmlobject", &ef);
3)qmlファイルで次のように呼び出します。
Item {
id: name
Connections
{
target:myqmlobject
onQmlvisiblechange:
{
if(is_foreground)
{
//dont do anything...
}
else
{
playSound.stop()
}
}
}
}
楽しみ :)
なぜ純粋なQMLの方法が必要なのですか?
イベントフィルターをインストールすることで、アプリケーションがバックグラウンドに送信されたかどうかを検出できます。チェック:http ://www.developer.nokia.com/Community/Wiki/Detecting_when_a_Qt_application_has_been_switched_to_the_background_and_when_resumed
「純粋な」QMLの方法には、Symbian
QML要素があります。http:
//doc.qt.nokia.com/qt-components-symbian/qml-symbian.html
foreground
アプリがフォアグラウンドにあるかバックグラウンドにあるかを示すプロパティがあります。に接続してみてくださいonForegroundChanged
。
ドキュメントから、Symbian
要素は「作成可能」ではありません。。という名前のコンテキストプロパティとして存在しますsymbian
。したがって、使用例は次のようになります。
import QtQuick 1.1
import com.nokia.symbian 1.1
PageStackWindow {
id: window
initialPage: MainPage {tools: toolBarLayout}
showStatusBar: true
showToolBar: true
function appForegroundChanged() {
console.log("Foreground: " + symbian.foreground)
}
function appCurrentTimeChanged() {
console.log("Current time: " + symbian.currentTime)
}
Component.onCompleted: {
symbian.currentTimeChanged.connect(appCurrentTimeChanged)
symbian.foregroundChanged.connect(appForegroundChanged)
}
ToolBarLayout {
id: toolBarLayout
ToolButton {
flat: true
iconSource: "toolbar-back"
onClicked: window.pageStack.depth <= 1 ? Qt.quit() : window.pageStack.pop()
}
}
}