2011-09-06 32 views
1

我正在編寫我的應用程序基礎和我正在使用pyside來開發應用程序。 我唯一的打嗝是讓qml開關激活。 目前我在QML文件:qml pyside和開關

signal buttonClicked; 
//function start(){text.text="started";buttonClicked()} 
Switch { 
    id:switchComponent 
    anchors.verticalCenterarent.verticalCenter; 
    anchors.horizontalCenterarent.horizontalCenter; 
} 
//end of switch 

Text { 
    id:text 

    color:"red" 
    anchors.bottom: switchComponent.top 
    anchors.horizontalCenter: switchComponent.horizontalCenter 
    //text: switchComponent.checked ? "GROUNDWORK ON" & start() : "Press to Start" 
    //text: switchComponent.checked ? "GROUNDWORK ON" && start() : "Press to Start" 
    text: switchComponent.checked ? start() : "Press to Start" 
    font.pixelSize: 30 
    smooth:true 
} 

應用程序啓動時,按下switchedComponent將信號發送到Python和連接到信號啓動,但開關從未變爲藍色和文本不會更改的功能「開始」。您知道應用程序正在運行的唯一方法是在大約10秒鐘之後,系統會要求您關閉該應用程序。如果你按NO,那麼應用程序將工作得很好。

有誰知道爲什麼會發生這種情況?我基本上只想在python函數開始運行之前啓動開關和文本,以便用戶知道發生了什麼。 編輯:完整的qml文件可以在這裏找到.https://projects.developer.nokia.com/airplay/browser/groundwork/qml/main.qml我認爲這只是使用pyside和qml的一部分,即ui線程塊在處理python函數時。

回答

0

我有點困惑你的代碼(和開關丟失),所以我只能猜測。

在Text組件中調用start()對我來說似乎是錯誤的。它應該只是

Text { 
    ... 
    text: switchComponent.checked ? "GROUNDWORK ON" : "Press to Start" 
} 

的文本沒有再被明確地設置和開關具有觸發您的組件的信號。

Switch { 
    onCheckedChanged: { 
     if (checked) { 
      buttonClicked() 
     } 
    } 
} 

這只是猜測與我的理解你的代碼。

+0

你在說什麼是有道理的,我試圖按照你的方式做,但我得到了同樣的結果。該程序的作品,但沒有迴應桂。我認爲qml的主要gui線程被阻塞,等待python任務完成。我想我將不得不在我的主要任務和被推送的交換機之間放置一個虛擬任務。 無論如何,現在我知道如何檢查狀態和狀態與一個按鈕,所以謝謝你。 – thegreattaurus