简体   繁体   中英

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

I wrote an application with 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. 2. User is able to select multiple folders and than execute a process(button) on all of those folders.

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.

The challenge is - How can my QThread use the 'selected folders list' from the main UI method???? 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.

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.

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.

So when you what to do something to that list in the thread run function, you can:

for item in self.ThreadList:
    do_something()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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