1

アプリケーションがバックグラウンドにあるかどうかを確認し、それに応じて音楽を停止または再生するための純粋なQMLの方法を知りたいです。meegoでは、PlatformWindow Elementを使用する別の方法がありますが、SymbianQMLには存在しません。助けが必要です

4

2 に答える 2

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()
            }
        }
    }
}

楽しみ :)

于 2012-05-28T08:20:48.913 に答える
1

なぜ純粋なQMLの方法が必要なのですか?

イベントフィルターをインストールすることで、アプリケーションがバックグラウンドに送信されたかどうかを検出できます。チェック:http ://www.developer.nokia.com/Community/Wiki/Detecting_when_a_Qt_application_has_been_switched_to_the_background_and_when_resumed

「純粋な」QMLの方法には、SymbianQML要素があります。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()
        }
    }
}
于 2012-05-27T13:52:46.773 に答える