使用 QTWebKit 显示存储在内存中的网站 [英] Using QTWebKit to display a website stored in memory

查看:24
本文介绍了使用 QTWebKit 显示存储在内存中的网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我将我的 HTML、JS、CSS、图形等存储在本地硬盘上,并使用 QWebFrame::SetUrl(QUrl::fromLocalFile("appFolder\html\index.html")).在某些时候,我将需要对本地存储的文件进行加密,因此我正在寻找一种方法来根据请求对它们进行解密,或者将它们全部解密到内存中并以这种方式访问​​它们.

Currently I have my HTML, JS, CSS, graphics, etc stored locally on hard disk and access them using QWebFrame::SetUrl( QUrl::fromLocalFile( "appFolder\html\index.html" )). At some point I am going to need to encrypt the locally stored files so I'm looking for a way to either decrypt them as they're requested or to decrypt them all into memory and access them that way.

我知道我可以使用 QWebFrame::setContent( htmlData ) 从内存中加载 HTML,这样我就可以加载加密的 HTML 文件,在内存中解密,然后以这种方式显示,但是如何我会处理当前存储在子文件夹中的其他数据(JS、CSS、图形等)吗?

I know I can use QWebFrame::setContent( htmlData ) to load the HTML from memory so I can load the encrypted HTML file, decrypt it in memory and then display it that way, but how would I go about the other data (JS, CSS, graphics, etc) which is currently stored in subfolders?

或者,有没有一种方法可以拦截访问所有 HTML、JS、CSS 等文件的请求,并在加载它们时对其进行解密?

Alternatively, is there a way I can intercept requests for access to all the HTML, JS, CSS, etc files and decrypt them as they're loaded?

通过使用我自己的 NetworkAccessManager 我可以拦截对 createRequest 的调用,这样我就可以看到每个文件何时被加载,但我看不到如何使用它即时解密数据.我还可以将插槽函数连接到 finished(QNetworkReply*) 信号,但此时数据已经被读取 - QIODevice 的当前位置指向文件末尾.

By using my own NetworkAccessManager I can intercept calls to createRequest so I can see when each file is being loaded, but I can't see how to use this to decrypt the data on the fly. I can also connect a slot function to the finished(QNetworkReply*) signal, but at that point the data has already been read - the QIODevice's current position is pointing to the end of the file.

如果您能提供任何正确方向的建议或指示,我将不胜感激.

I'd be very grateful for any advice or pointers in the right direction.

推荐答案

我认为在您的情况下最好的解决方案是继承 QNetworkReply 类并在重新实现的 QNetworkAccessManager:: 中使用这个新类createRequest() 函数.

I think in your case the best solution is to inherit QNetworkReply class and use this new class in reimplemented QNetworkAccessManager::createRequest() function.

通常,您应该重新实现 QNetworkReply 的下一个虚拟功能:bytesAvailable()readData(char *data, qint64 maxSize)close()abort().

In general, you should reimplement next virtual functions of QNetworkReply: bytesAvailable(), readData(char *data, qint64 maxSize), close(), abort().

例如,readData 应该如下:

qint64 NetworkReplyEx::readData(char *data, qint64 maxSize)
{
    return m_buffer.read(data, maxSize);
}

其中 m_buffer 是已经解密的数据.

where m_buffer is already decrypted data.

你还需要在这个类中添加所有必要的逻辑来获取加密数据,解密这些数据......最后,您应该在新类中手动发出 finished() 信号,以便 QWebView 或其他相关类将获得解密的 html.

Also you need to add all necessary logic in this class to get encrypted data, decrypt this data... In the end you should manually emit finished() signal inside new class, so QWebView or other related class will get decrypted html.

这篇关于使用 QTWebKit 显示存储在内存中的网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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