简体   繁体   English

如何在Pyside,QtPy python中从主UI到Qthread发送列表?

[英]How to send a list from the main UI TO Qthread in Pyside, QtPy python?

I wrote an application with Pyside(QtPy). 我用Pyside(QtPy)编写了一个应用程序。 The application allows the user to: 1. Scan a path - Application will scan a default path and display the existing folders in that path as a list of check boxes. 该应用程序允许用户:1.扫描路径-应用程序将扫描默认路径并将该路径中的现有文件夹显示为复选框列表。 2. User is able to select multiple folders and than execute a process(button) on all of those folders. 2.用户能够选择多个文件夹,然后对所有这些文件夹执行一个过程(按钮)。

In the background: when the user hit 'process', I scan the check boxes list and create a new list only for the selected folder (the 'checked' check boxes or 'user selected folders'). 在后台:当用户单击“处理”时,我扫描复选框列表并仅为所选文件夹(“选中的”复选框或“用户所选的文件夹”)创建一个新列表。

The actual process to those folders will be running in a loop in a QThread class. 这些文件夹的实际过程将在QThread类中循环运行。

The challenge is - How can my QThread use the 'selected folders list' from the main UI method???? 挑战是-我的QThread如何使用主UI方法中的“选定文件夹列表”? At this point the only way I was able to make it work, is by making this list a global parameter. 在这一点上,我能够使之生效的唯一方法是使该列表成为全局参数。 Main UI method set values to the global list, QThread can read that global list. 主UI方法将值设置为全局列表,QThread可以读取该全局列表。

I've read all possible documentation on signals and slots, and I have no problem sending anything I want from the Qthread to the main UI, but I couldn't find a decent explanation for sending data TO a thread. 我已经阅读了有关信号和插槽的所有可能的文档,并且从Qthread向主UI发送任何想要的东西都没有问题,但是我找不到关于向线程发送数据的正当解释。

Thank you. 谢谢。

Actually, I ended up with a very simple solution. 实际上,我最终得到了一个非常简单的解决方案。 I set my list, in a new list, in the thread object. 我在线程对象的新列表中设置了列表。

self.runningProcess = clMyThread()  #This is my thread object
self.runningProcess.ThreadList = self.MainList

self.MainList will be whatever list you got in the UI as the input while the ThreadList is the same list in the thread itself. self.MainList将是您在UI中获得的任何列表作为输入,而ThreadList是线程本身中的相同列表。

So when you what to do something to that list in the thread run function, you can: 因此,当您要对线程运行功能中的列表进行操作时,可以:

for item in self.ThreadList:
    do_something()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM