2013-08-06 28 views
1

我想在用戶點擊應用程序圖標時顯示一個啓動頁面。爲此,我創建了工作表並將其附加到頁面上。 main.qml如何在qml中關閉表單?

import bb.cascades 1.0 

Page { 
    Container { 
     Label { 
      text: "Home page" 
      verticalAlignment: VerticalAlignment.Center 
      horizontalAlignment: HorizontalAlignment.Center 
     } 
    } 
    attachedObjects: [ 
     Sheet { 
      id: mySheet 
      content: Page { 
       Label { 
        text: "Splash Page/Sheet." 
       } 
      } 
     } 
    ]//end of attached objects 
    onCreationCompleted: { 

     //open the sheet 
     mySheet.open(); 

     //After that doing some task here. 
     --------- 
     --------- 
     --------- 

     //Now I'm closing the Sheet. But the Sheet was not closed. 
     //It is showing the Sheet/Splash Page only, not the Home Page 
     mySheet.close(); 
    } 
}//end of page 

工作完成後,我想關閉表。所以我調用了close()方法。但是Sheet沒有關閉。

如何關閉oncreationCompleted()方法或任何C++方法中的工作表?

+0

您是否嘗試在mySheet.close()之前/之後放置一個日誌,只是爲了確保達到它? –

+0

是的,我測試過了,它也打印日誌消息。 – user2636874

+1

您的任務需要多長時間?當您嘗試關閉它時,可能表單尚未完全打開(動畫可能未結束)。 –

回答

1

您正試圖在打開完成之前關閉Sheet(動畫仍在運行),因此關閉請求會被忽略。您必須監視動畫的結尾(opened()信號)以瞭解您的Sheet是否已打開。我會這樣做:

import bb.cascades 1.0 

Page { 
    Container { 
     Label { 
      text: "Home page" 
      verticalAlignment: VerticalAlignment.Center 
      horizontalAlignment: HorizontalAlignment.Center 
     } 
    } 
    attachedObjects: [ 
     Sheet { 
      id: mySheet 
      property finished bool: false 
      content: Page { 
       Label { 
        text: "Splash Page/Sheet." 
       } 
      } 
      // We request a close if the task is finished once the opening is complete 
      onOpened: { 
       if (finished) { 
        close(); 
       } 
      } 
     } 
    ]//end of attached objects 
    onCreationCompleted: { 

     //open the sheet 
     mySheet.open(); 

     //After that doing some task here. 
     --------- 
     --------- 
     --------- 

     //Now I'm closing the Sheet. But the Sheet was not closed. 
     //It is showing the Sheet/Splash Page only, not the Home Page 
     mySheet.finished = true; 
     // If the Sheet is opened, we close it 
     if (mySheet.opened) { 
      mySheet.close(); 
     } 
    } 
}//end of page
+0

注意,對於某些操作系統,此信號不會發送。我不得不使用QTimer並檢查「isOpened()」狀態手動關閉它 – Benoit

+0

而不是直接在onOpened()方法中關閉工作表,我試着按照代碼中提到的方法操作。然後表單不關閉。 – user2636874

+0

添加console.log(「onOpened」);確保這個插槽被調用 – Benoit