How can I set a QFileSystemModel with information from another PC?

孤街醉人 提交于 2021-02-10 13:38:11

问题


I'm doing a college project where we need to set up a dropbox-like service in a local network. I can do it easily in a terminal, but for some extra points I'm trying to set up an QtPy ui for it.

One of my widgets it's a QTreeView with a QFileSystemModel where I'd like to visualize the files and folders the user has saved on his "dropbox". The thing is, that the information and the folder itself are in another computer. I've tried sending the widget from one pc to another but you can't pickle widgets. I've also tried sending the 'self.model' and add it later but it didn't work. Any solutions? Here's the Widget Code:

class MyFolder(*form):

    def __init__(self):
        super().__init__()
        self.client = ""
        self.setupUi(self)
        self.model = QtGui.QFileSystemModel()
        self.model.setRootPath("./Archivos/MyFolder")
        self.myFolder.setModel(self.model)
        self.myFolder.setRootIndex(self.model.index("./Archivos/MyFolder"))
        self.addButton.clicked.connect(self.addDialog)

回答1:


The short answer is you can't do that directly. As stated by the documentation:

The QFileSystemModel class provides a data model for the local filesystem

  • On the other hand as long as the underlying O.S can represent the remote filesystem as a local one, it is possible for QT to display it as a local filesystem with a QFileSystemModel.

Every remote filesystem that can be represented locally (using protocols such as HTTP, (s)FTP, SMB (CIFS; Samba), SSH protocols and possible other sources), can also be represented in a QFileSystemModel.

For instance on Windows you can "mount" a remote filesystem (for ex. by using using a SMB share) on a dedicated drive letter. In this case the remote filesystem is availabe exactly as a local one and it is transparent to any application using the mounted local drive.

  • Another solution is to serialize the remote filesystem and un-serialize it on your local system as explained here on SO.


来源:https://stackoverflow.com/questions/33855592/how-can-i-set-a-qfilesystemmodel-with-information-from-another-pc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!