qml pyside 和开关

发布于 2024-12-03 08:23:37 字数 1136 浏览 1 评论 0原文

我正在对我的应用程序 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,并且连接到信号的函数启动,但开关永远不会变成蓝色,并且文本不会更改为“started”。您知道应用程序正在运行的唯一方法是大约 10 秒后,系统会要求您关闭应用程序。如果您按“否”,那么该应用程序将正常工作。

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

I am coding my application Groundwork and I am using pyside to develop the application.
The only hiccup I am having is getting the qml switch to activate.
Currently I have in the qml file:

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
}

When the application starts, pressing the switchedComponent sends the signal to python and the function connected to the signal starts but the switch never turns blue and the text does not change to "started". The only way you know the application is running is that after ~10 seconds they system will ask you to close the application. If you press NO then the app will work just fine.

Does anyone know why this happens? I basically just want the switch and text to activate before the python function starts running so the user knows whats happening.
Edit: The full qml file can be found here.https://projects.developer.nokia.com/airplay/browser/groundwork/qml/main.qml I think this is just a part of using pyside with qml that the ui thread block when processing python functions.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

上课铃就是安魂曲 2024-12-10 08:23:37

我对你的代码有点困惑(并且开关丢失了)所以我只能猜测。

在我看来,在 Text 组件中调用 start() 是错误的。它应该只是

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

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

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

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

I'm a little bit confused by your code (and the Switch is missing) so I can only guess.

Calling start() in the Text component seems wrong to me. It should only be

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

The text doesn't have to be set explicitely anymore and the switch has to trigger the signal of your component.

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

This is just guessing with my understanding of your code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文