【问题标题】:Why does my log message not execute first?为什么我的日志消息没有先执行?
【发布时间】:2022-11-04 21:11:44
【问题描述】:

最近我一直在用 PySide6 (Qt) 为我的 python 脚本构建一个 GUI。我添加了一个按钮,在按下时执行我的脚本:

def button_start_collecting(self):
        if not self.input_src.text():
            self.log_message("Please add the missing source path")
        if not self.input_dest.text():
            self.log_message("Please add the missing destination path")
        else:
            self.log_message("Starting to collect...")
            execute_pvt(self.dest, self.origin)
            self.log_message("The files and directories have been collected")

我的问题是,我希望在脚本本身执行之前日志消息出现在我的日志小部件上,但它没有显示出来。只有在执行完成后,两条日志消息才会同时出现。就好像代码的结构如下:

else:
           
            execute_pvt(self.dest, self.origin)
            self.log_message("Starting to collect...")
            self.log_message("The files and directories have been collected")

有人知道如何解决这个问题吗?

【问题讨论】:

  • 如果预计没有其他 UI 元素与用户交互,并且在 execute_pvt 中完成的操作不会花费太多时间,请在第一个 log_message 之后立即调用 QApplication.processEvents()。否则,请为此使用 threading/QThread。

标签: python qt pyside pyside6


【解决方案1】:

该问题可以通过在不同线程上执行 execute_pvt() 来解决。

【讨论】:

    猜你喜欢
    • 2017-06-30
    • 1970-01-01
    • 1970-01-01
    • 2020-09-26
    • 1970-01-01
    • 1970-01-01
    • 2021-07-11
    • 1970-01-01
    • 2018-09-05
    相关资源
    最近更新 更多