How to load a web page from resources in Qt?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-10 11:53:20

问题


If we put a webpage in resources, how can we load it in webkit?


回答1:


I don't know if I understood correctly, but I suppose you have a web page like a test.html file, and you want it to be loaded in a QWebView. This is quite simple:

#include <QtGui/QApplication>
#include <QWebView>

int main(int argc, char* argv[])
{
    QApplication a(argc, argv);
    QWebView view;
    view.setUrl(QUrl("qrc:/test.html"));
    view.show();
    return a.exec();
}

The file has to be placed in a Qt resource file. Remember to add:

QT += webkit

to your .pro file.



来源:https://stackoverflow.com/questions/8020569/how-to-load-a-web-page-from-resources-in-qt

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