2012-05-25 101 views

回答

2

最后我得到它的工作:)我做到了,虽然Qt的方式......这里的步骤

1)创建一个类MyEventFilter

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

享受:)

1

为什么你需要一个纯粹的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

它有一个​​属性,指示应用是否在前台或后台。您可以尝试连接到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() 
     } 
    } 
} 
+0

我想一个纯QML方式我吸在Qt编程...我看过您提供的第二个链接..但不知何故,我QtCreator在qml中没有Symbian标签。你可以在你的QtCreator中试用它,让我知道我错过了什么。我安装了QtSdk 1.1并且也使用了QtQuick 1.1。仍然Symbian标签不能被我的ide ... – SoH

+0

检查我编辑的答案。 – sabbour

相关问题