QT - QFileSystemModel在服务器客户端程序 [英] QT - QFileSystemModel on server-client program

查看:248
本文介绍了QT - QFileSystemModel在服务器客户端程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个服务器 - 客户端QT项目,允许在服务器和客户端之间传输文件。作为一个GUI项目,我想在客户端程序上显示服务器的文件系统,就像一个文件浏览器。



问题是:有没有办法将QFileSystemModel或QFileSystemWatcher从服务器发送到客户端,或者在客户端显示服务器的系统文件?谢谢。

解决方案

解决这个问题的最佳方法是为你的对象实现一个序列化技术。一旦这样做,你需要实现规则来在通信协议层交换这样的序列化对象。



例如,你可以这样序列化一个路径:

 文件大小 -  8bytes;路径标志 -  1byte;路径大小 -  2bytes;实际路径 - `路径大小字节; 

在文件大小字段中,您可以保存路径指向的文件的大小,字段,您将在路径大小和路径大小以及实际路径字段(显然)路径中保存有关文件的其他信息(例如,如果它是目录/文件等)。



例如,假设我想通过设置标志字段中的位0来区分文件/目录:文件为1,目录为0。保存512MB文件(例如'/ abc / d / efg')的目录路径将序列化为(使用 | 作为字段分隔符):

$ b $

  536870912 | 0 | 10 | / abc / d / efg 

要序列化目录树,并将字节存储在向量中。要序列化向量,你只需要添加一个前缀(例如4字节),指定它包含的文件数量;例如,以下格式的流:

  2 | (536870912 | 0 | 10 | / abc / d / efg),(536870912 | 0 | 10 | / abc / d / efh)

告诉我,我有两个文件路径条目大小512MB,两个目录一个名称 / abc / d / efg / 现在你知道如何对目录树进行序列化/反序列化了。

现在你知道如何对目录树进行序列化/反序列化。要将其发送给另一方,我首先向序列化对象添加唯一的消息ID类型(以便另一方知道接收的是什么),然后将其发送。



最后,给定上面的两个条目,假设我用 0x00 为这种类型的序列化对象添加前缀,最终的流将如下所示:



0 | 2 | (536870912 | 0 | 10 | / abc / d / efg),(536870912 | 0 | 10 | / abc / d / efh)


I am working on a server-client QT project that allows to transfer files between server and client. Being a GUI project, I want to display the server's file system on client program, like a file explorer.

The question is : is there a way to send the QFileSystemModel or QFileSystemWatcher from server to client, or to display the server's system file on client side? Thank you.

解决方案

The best approach to tackle this problem is to implement a serialization technique for your object(s). Once that's done you'd need to implement rules to exchange such serialized objects at the communication protocol level.

For instance, you could serialize a path like this:

file size - 8bytes; path flags - 1byte; path size - 2bytes; actual path - `path size` bytes;

In the file size field you'd save the size of the file pointed by the path, in flags field you'd save additional information about the file (eg. if it's a directory/file etc.;) in the path size the size of the path and in the actual path field, (obviously) the path.

For example, say I want to distinguish between files/directories by setting bit 0 in the flags field: 1 for files, 0 for directories. A directory path that holds 512MB of files such as '/abc/d/efg' would be serialized as (using | as field delimiter):

536870912 | 0 | 10 | /abc/d/efg

To serialize a directory tree you'd just serialize every file in in there and store the bytes in a vector. To serialize the vector you'd just add a prefix to it (say 4 bytes) specifying the number of files it contains; For example, a stream in this format:

2 | (536870912 | 0 | 10 | /abc/d/efg), (536870912 | 0 | 10 | /abc/d/efh)

Would tell me that I have 2 file path entries both of size 512MB, both directories one with name /abc/d/efg/ and one with name /abc/d/efh.

Now you know how to serialize/deserialize a directory tree. To send it over to the other party I'd first prefix my serialized object with a unique message id type (so that the other party knows what it is receiving) and then send it over.

So in the end, given the two entries above, and assuming I prefix this type of serialized object with 0x00 the final stream would look like:

0 | 2 | (536870912 | 0 | 10 | /abc/d/efg), (536870912 | 0 | 10 | /abc/d/efh)

这篇关于QT - QFileSystemModel在服务器客户端程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆