1

我正在编写我的应用程序 Groundwork 并且我正在使用 pyside 来开发应用程序。我唯一遇到的问题是激活 qml 开关。目前我在 qml 文件中有:

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 秒后系统会要求您关闭应用程序。如果您按否,则该应用程序将正常工作。

有谁知道为什么会这样?我基本上只是希望在 python 函数开始运行之前激活开关和文本,以便用户知道发生了什么。编辑:完整的 qml 文件可以在这里找到。 https://projects.developer.nokia.com/airplay/browser/groundwork/qml/main.qml 我认为这只是将 pyside 与 qml 一起使用的一部分,即 ui 线程处理python函数时阻塞。

4

1 回答 1

0

我对您的代码有点困惑(并且缺少 Switch),所以我只能猜测。

在 Text 组件中调用 start() 对我来说似乎是错误的。它应该只是

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

文本不再需要明确设置,开关必须触发组件的信号。

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

这只是我对您代码的理解的猜测。

于 2011-09-06T06:56:03.737 回答