[英]How to include webview in existing Qt project?
I am trying to include one of the following libraries:我正在尝试包含以下库之一:
#include <QtWebView>
#include <QWebView>
#include <QtWebEngineWidgets>
#include <WebEngineCore>
#include <QtWebEngine>
Each time I add one of its includes an error appears in my code.每次我添加其中一个包含时,我的代码中都会出现一个错误。 However, I use Qt 6.3.1 and I find files that correspond to the includes in my system installation folder under macOS.
但是,我使用 Qt 6.3.1,并且在 macOS 下的系统安装文件夹中找到了与包含对应的文件。 I use a cmake in my qt project and not a file.pro or qmake.
我在我的 qt 项目中使用 cmake 而不是 file.pro 或 qmake。
Ultimately, I want to display a web form in my UI.最终,我想在我的 UI 中显示一个 web 表单。
Maybe you need to add WebEngineWidgets
module to your cmake file也许您需要将
WebEngineWidgets
模块添加到您的 cmake 文件中
find_package(Qt6 REQUIRED COMPONENTS WebEngineWidgets)
target_link_libraries(mytarget PRIVATE Qt6::WebEngineWidgets)
then #include <QWebEngineView>
然后
#include <QWebEngineView>
https://doc.qt.io/qt-6/qwebengineview.html https://doc.qt.io/qt-6/qwebengineview.html
You need to make sure that you install the QtWebEngine
module when installing Qt.安装 Qt 时需要确保安装了
QtWebEngine
模块。
Then, in your CMakeLists.txt
, you would write something like this below.然后,在您的
CMakeLists.txt
中,您将在下面编写类似这样的内容。
Please note that you should use versionless targets as recommended by the Qt Project , ie do not use Qt6::WebEngineWidgets
as that would have portability issues.请注意,您应该使用Qt 项目推荐的无版本目标,即不要使用
Qt6::WebEngineWidgets
,因为这会产生可移植性问题。
find_package(Qt6 COMPONENTS WebEngineWidgets REQUIRED)
target_link_libraries(YourTarget Qt::WebEngineWidgets)
add_executable(YourTarget main.cpp)
Then, you can just write something like this in your main.cpp
:然后,您可以在
main.cpp
中编写类似这样的内容:
#include <QApplication>
#include <QWebEngineView>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWebEngineView view;
view.setUrl(QUrl(QStringLiteral("https://www.qt.io")));
view.show();
return app.exec();
}
Please refer to the official examples for further details.请参阅官方示例以获取更多详细信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.