### Installing the Executable Source: https://github.com/qt/qtwebengine/blob/dev/examples/webenginewidgets/videoplayer/CMakeLists.txt Installs the built 'videoplayer' target to the specified example directory on the system. ```cmake install(TARGETS videoplayer RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) ``` -------------------------------- ### Install Directory Configuration Source: https://github.com/qt/qtwebengine/blob/dev/examples/webenginewidgets/videoplayer/CMakeLists.txt Defines the installation directory for the example, ensuring it's placed correctly within the examples structure. ```cmake if(NOT DEFINED INSTALL_EXAMPLESDIR) set(INSTALL_EXAMPLESDIR "examples") endif() set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/webenginewidgets/videoplayer") ``` -------------------------------- ### Define Installation Directory Source: https://github.com/qt/qtwebengine/blob/dev/examples/webenginewidgets/spellchecker/CMakeLists.txt Sets the installation directory for the example, ensuring it's correctly placed within the Qt installation structure. ```cmake if(NOT DEFINED INSTALL_EXAMPLESDIR) set(INSTALL_EXAMPLESDIR "examples") endif() set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/webenginewidgets/spellchecker") ``` -------------------------------- ### Installation Configuration Source: https://github.com/qt/qtwebengine/blob/dev/examples/webenginewidgets/contentmanipulation/CMakeLists.txt Configures the installation of the application executable, placing it in the specified example directory based on the target platform. ```cmake install(TARGETS contentmanipulation RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) ``` -------------------------------- ### CMake Project Setup Source: https://github.com/qt/qtwebengine/blob/dev/examples/pdf/multipage/CMakeLists.txt Sets the minimum CMake version, project name, and languages. Configures installation directories for examples. ```cmake cmake_minimum_required(VERSION 3.16) project(multipage LANGUAGES CXX) if(NOT DEFINED INSTALL_EXAMPLESDIR) set(INSTALL_EXAMPLESDIR "examples") endif() set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/pdf/multipage") find_package(Qt6 REQUIRED COMPONENTS Gui Qml OPTIONAL_COMPONENTS Svg) if(NOT TARGET Qt::Svg) message(WARNING "QtSvg is required as runtime dependency for qtpdfquick examples.") endif() qt_standard_project_setup(REQUIRES 6.8) ``` -------------------------------- ### Installation Rules Source: https://github.com/qt/qtwebengine/blob/dev/examples/webenginequick/lifecycle/CMakeLists.txt Defines how the application executable and its related files should be installed. This ensures the example can be deployed correctly. ```cmake install(TARGETS lifecycle RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) ``` -------------------------------- ### Setup Video Element and Get Display Media Source: https://github.com/qt/qtwebengine/blob/dev/tests/manual/widgets/webrtc/index.html Initializes a video element and provides functions to start and stop the display media stream. Ensure the 'content' element exists in your HTML. ```javascript const content = document.getElementById("content"); const video = document.createElement("video"); video.setAttribute("width", 640); video.setAttribute("height", 640); video.setAttribute("style", "background-color: black;"); content.appendChild(video); ``` ```javascript async function getDisplayMedia(v = true, a = true) { stop(); navigator.mediaDevices.getDisplayMedia({ video: v, audio: a }) .then(stream => { start(stream); }, error => { console.error(error); }); } ``` ```javascript function stop() { if (video.srcObject) for (const track of video.srcObject.getTracks()) track.stop() video.srcObject = null; video.setAttribute("style", "background-color: black;"); } ``` ```javascript function start(stream) { video.srcObject = stream; video.play(); } ``` -------------------------------- ### Installation Directory Configuration Source: https://github.com/qt/qtwebengine/blob/dev/examples/webenginewidgets/maps/CMakeLists.txt Defines the installation directory for examples, ensuring consistency across platforms. ```cmake if(NOT DEFINED INSTALL_EXAMPLESDIR) set(INSTALL_EXAMPLESDIR "examples") endif() set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/webenginewidgets/maps") ``` -------------------------------- ### Basic CMake Configuration for Qt Examples Source: https://github.com/qt/qtwebengine/blob/dev/examples/CMakeLists.txt Sets the minimum required CMake version and begins the example build process. This is a standard setup for Qt examples. ```cmake cmake_minimum_required(VERSION 3.16) qt_examples_build_begin(EXTERNAL_BUILD) ``` -------------------------------- ### Project Setup and Dependencies Source: https://github.com/qt/qtwebengine/blob/dev/examples/webenginewidgets/notifications/CMakeLists.txt Configures the CMake build for the notifications example, specifying the minimum CMake version, project name, and required Qt modules (Core, Gui, WebEngineWidgets). ```cmake cmake_minimum_required(VERSION 3.16) project(notifications LANGUAGES CXX) set(CMAKE_AUTOMOC ON) if(NOT DEFINED INSTALL_EXAMPLESDIR) set(INSTALL_EXAMPLESDIR "examples") endif() set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/webenginewidgets/notifications") find_package(Qt6 REQUIRED COMPONENTS Core Gui WebEngineWidgets) ``` -------------------------------- ### Install Spellchecker Executable Source: https://github.com/qt/qtwebengine/blob/dev/examples/webenginewidgets/spellchecker/CMakeLists.txt Installs the built spellchecker executable to the designated example directory. ```cmake install(TARGETS spellchecker RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) ``` -------------------------------- ### CMakeLists.txt for PrintMe Example Source: https://github.com/qt/qtwebengine/blob/dev/examples/webenginewidgets/printme/CMakeLists.txt Configures the build for the PrintMe Qt WebEngine example. It sets up the project, finds required Qt modules, defines the executable, links libraries, and manages resource files. ```cmake # Copyright (C) 2022 The Qt Company Ltd. # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause cmake_minimum_required(VERSION 3.16) project(printme LANGUAGES CXX) set(CMAKE_AUTOMOC ON) if(NOT DEFINED INSTALL_EXAMPLESDIR) set(INSTALL_EXAMPLESDIR "examples") endif() set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/webenginewidgets/printme") find_package(Qt6 REQUIRED COMPONENTS Core Gui PrintSupport WebEngineWidgets) qt_add_executable(printme main.cpp printhandler.cpp printhandler.h ) set_target_properties(printme PROPERTIES WIN32_EXECUTABLE TRUE MACOSX_BUNDLE TRUE ) target_link_libraries(printme PUBLIC Qt::Core Qt::Gui Qt::PrintSupport Qt::WebEngineWidgets ) # Resources: set(data_resource_files "data/index.html" "data/style.css" ) qt_add_resources(printme "data" PREFIX "/" BASE "data" FILES ${data_resource_files} ) install(TARGETS printme RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) ``` -------------------------------- ### Basic CMake Setup for Spellchecker Source: https://github.com/qt/qtwebengine/blob/dev/examples/webenginewidgets/spellchecker/CMakeLists.txt Sets up the minimum CMake version, project name, and enables automatic meta-object compilation. This is a standard starting point for Qt CMake projects. ```cmake cmake_minimum_required(VERSION 3.16) project(spellchecker LANGUAGES CXX) set(CMAKE_AUTOMOC ON) ``` -------------------------------- ### Installation Rules Source: https://github.com/qt/qtwebengine/blob/dev/examples/webenginewidgets/simplebrowser/CMakeLists.txt Defines installation rules for the 'simplebrowser' target, specifying where the executable, bundle, and libraries should be placed. ```cmake install(TARGETS simplebrowser BUNDLE DESTINATION . RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ) ``` -------------------------------- ### Project Setup and Dependencies Source: https://github.com/qt/qtwebengine/blob/dev/examples/webenginequick/lifecycle/CMakeLists.txt Configures the build system, finds necessary Qt modules, and sets up the project structure. Ensure Qt 6.8 or later is available. ```cmake cmake_minimum_required(VERSION 3.16) find_package(Qt6 REQUIRED COMPONENTS Core Gui QuickControls2 WebEngineQuick) qt_standard_project_setup(REQUIRES 6.8) ``` -------------------------------- ### Installation Rules Source: https://github.com/qt/qtwebengine/blob/dev/examples/pdf/multipage/CMakeLists.txt Defines the installation rules for the multipage executable, specifying runtime, bundle, and library destinations. ```cmake install(TARGETS multipage RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) ``` -------------------------------- ### Installation Configuration Source: https://github.com/qt/qtwebengine/blob/dev/examples/webenginewidgets/notifications/CMakeLists.txt Configures the installation of the notifications executable, specifying the destination directory for runtime binaries, bundles, and libraries. ```cmake install(TARGETS notifications RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) ``` -------------------------------- ### Ending Qt Example Build Configuration Source: https://github.com/qt/qtwebengine/blob/dev/examples/CMakeLists.txt Completes the example build process. This function is part of Qt's example build system helpers. ```cmake qt_examples_build_end() ``` -------------------------------- ### Find and Setup Qt Components Source: https://github.com/qt/qtwebengine/blob/dev/src/host/CMakeLists.txt Finds the required Qt 6.5 configuration and components, then sets up the internal project structure. ```cmake find_package(Qt6 6.5 CONFIG REQUIRED COMPONENTS BuildInternals Core) qt_internal_project_setup() ``` -------------------------------- ### Installing the Executable Source: https://github.com/qt/qtwebengine/blob/dev/examples/webenginewidgets/maps/CMakeLists.txt Installs the maps executable to a specified runtime destination. ```cmake install(TARGETS maps RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) ``` -------------------------------- ### Install GN Executable Source: https://github.com/qt/qtwebengine/blob/dev/src/gn/CMakeLists.txt Installs the generated GN executable to the bin directory. ```cmake install(PROGRAMS ${GN_BINARY_DIR}/$/${GN_EXECUTABLE} DESTINATION bin ) ``` -------------------------------- ### Setting Install Directory Source: https://github.com/qt/qtwebengine/blob/dev/src/CMakeLists.txt Defines the installation directory for build artifacts. ```cmake set(installDir ${PROJECT_BINARY_DIR}/install) ``` -------------------------------- ### Project Setup and Dependencies Source: https://github.com/qt/qtwebengine/blob/dev/examples/webenginewidgets/cookiebrowser/CMakeLists.txt Configures the CMake version, project name, and finds required Qt6 components like Core, Gui, and WebEngineWidgets. ```cmake cmake_minimum_required(VERSION 3.16) project(cookiebrowser LANGUAGES CXX) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTOUIC ON) if(NOT DEFINED INSTALL_EXAMPLESDIR) set(INSTALL_EXAMPLESDIR "examples") endif() set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/webenginewidgets/cookiebrowser") find_package(Qt6 REQUIRED COMPONENTS Core Gui WebEngineWidgets) ``` -------------------------------- ### Installation Rules Source: https://github.com/qt/qtwebengine/blob/dev/examples/webenginewidgets/cookiebrowser/CMakeLists.txt Specifies the installation paths for the 'cookiebrowser' executable on different platforms. ```cmake install(TARGETS cookiebrowser RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) ``` -------------------------------- ### Toolchain Setup for Linux and Windows Source: https://github.com/qt/qtwebengine/blob/dev/src/pdf/CMakeLists.txt Sets up the toolchain for building on Linux, MinGW, Android, or Windows platforms. This is a conditional setup based on the operating system. ```cmake if(LINUX OR MINGW OR ANDROID OR WIN32) setup_toolchains() endif() ``` -------------------------------- ### Project Setup and Executable Definition Source: https://github.com/qt/qtwebengine/blob/dev/examples/webenginewidgets/simplebrowser/CMakeLists.txt Defines the minimum CMake version, project name, and finds required Qt6 components. It then adds the main executable 'simplebrowser' with its source files. ```cmake cmake_minimum_required(VERSION 3.16) project(simplebrowser LANGUAGES CXX) find_package(Qt6 REQUIRED COMPONENTS Core Gui WebEngineWidgets) qt_standard_project_setup() qt_add_executable(simplebrowser browser.cpp browser.h browserwindow.cpp browserwindow.h certificateerrordialog.ui downloadmanagerwidget.cpp downloadmanagerwidget.h downloadmanagerwidget.ui downloadwidget.cpp downloadwidget.h downloadwidget.ui main.cpp passworddialog.ui tabwidget.cpp tabwidget.h webpage.cpp webpage.h webpopupwindow.cpp webpopupwindow.h webview.cpp webview.h webauthdialog.cpp webauthdialog.h webauthdialog.ui ) ``` -------------------------------- ### Basic CMake Project Setup Source: https://github.com/qt/qtwebengine/blob/dev/examples/webenginewidgets/maps/CMakeLists.txt Sets the minimum CMake version, project name, and enables automatic meta-object compilation. ```cmake cmake_minimum_required(VERSION 3.16) project(maps LANGUAGES CXX) set(CMAKE_AUTOMOC ON) ``` -------------------------------- ### Generate Deploy App Script Source: https://github.com/qt/qtwebengine/blob/dev/examples/webenginewidgets/simplebrowser/CMakeLists.txt Generates a deployment script for the 'simplebrowser' application using 'qt_generate_deploy_app_script' and installs it. ```cmake qt_generate_deploy_app_script( TARGET simplebrowser OUTPUT_SCRIPT deploy_script NO_UNSUPPORTED_PLATFORM_ERROR ) install(SCRIPT ${deploy_script}) ``` -------------------------------- ### Append Compiler/Linker SDK Setup to GN Arguments Source: https://github.com/qt/qtwebengine/blob/dev/src/core/CMakeLists.txt Appends compiler, linker, and SDK setup to a list of GN arguments. ```cmake append_compiler_linker_sdk_setup(gnArgArg) ``` -------------------------------- ### Toolchain and GN Build Setup Source: https://github.com/qt/qtwebengine/blob/dev/src/core/CMakeLists.txt Sets up toolchains for Linux and Windows and adds core GN build targets. It also retrieves configurations and architectures for further build customization. ```cmake if(LINUX OR WIN32) setup_toolchains() endif() addSyncTargets(core) get_configs(configs) get_architectures(archs) ``` -------------------------------- ### QWebChannel Setup and Signal/Slot Connection Source: https://github.com/qt/qtwebengine/blob/dev/tests/auto/quick/qmltests/data/webchannel-test.html Initializes QWebChannel, exposes a test object, and connects a signal to a slot for testing purposes. Ensure the QWebChannel module is available in your web environment. ```javascript //BEGIN SETUP var channel = new QWebChannel(qt.webChannelTransport, function(channel) { window.testObject = channel.objects.testObject; testObject.runTest.connect(function(foo) { testObject.foo = foo; testObject.bar(foo); }); testObject.clientInitialized(testObject.foo); }); //END SETUP ``` -------------------------------- ### Basic CMake Project Setup Source: https://github.com/qt/qtwebengine/blob/dev/examples/webenginewidgets/videoplayer/CMakeLists.txt Sets the minimum CMake version and project name. Configures automatic handling of Qt's Meta-Object Compiler (MOC). ```cmake cmake_minimum_required(VERSION 3.16) project(videoplayer LANGUAGES CXX) set(CMAKE_AUTOMOC ON) ``` -------------------------------- ### CMake Build Configuration for html2pdf Source: https://github.com/qt/qtwebengine/blob/dev/examples/webenginewidgets/html2pdf/CMakeLists.txt This CMake script sets up the build environment for the html2pdf example. It defines the project, enables automatic meta-object compilation, finds required Qt components, and configures the executable and its installation. ```cmake cmake_minimum_required(VERSION 3.16) project(html2pdf LANGUAGES CXX) set(CMAKE_AUTOMOC ON) if(NOT DEFINED INSTALL_EXAMPLESDIR) set(INSTALL_EXAMPLESDIR "examples") endif() set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/webenginewidgets/html2pdf") find_package(Qt6 REQUIRED COMPONENTS Core Gui WebEngineWidgets) qt_add_executable(html2pdf html2pdf.cpp ) set_target_properties(html2pdf PROPERTIES WIN32_EXECUTABLE TRUE MACOSX_BUNDLE TRUE ) target_link_libraries(html2pdf PUBLIC Qt::Core Qt::Gui Qt::WebEngineWidgets ) install(TARGETS html2pdf RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) ``` -------------------------------- ### Append Sanitizer Setup to GN Arguments Source: https://github.com/qt/qtwebengine/blob/dev/src/core/CMakeLists.txt Appends sanitizer setup configurations to a list of GN arguments. ```cmake append_sanitizer_setup(gnArgArg) ``` -------------------------------- ### Begin SBOM for Qt Repo Project Source: https://github.com/qt/qtwebengine/blob/dev/src/CMakeLists.txt Starts the Software Bill of Materials (SBOM) generation for the Qt repository project. This is typically done before processing modules that require SBOM tracking. ```cmake qt_internal_sbom_begin_qt_repo_project() ``` -------------------------------- ### Append Pkg-Config Setup to GN Arguments Source: https://github.com/qt/qtwebengine/blob/dev/src/core/CMakeLists.txt Appends pkg-config related setup to a list of GN arguments. ```cmake append_pkg_config_setup(gnArgArg) ``` -------------------------------- ### GN Build Setup for PDF Module Source: https://github.com/qt/qtwebengine/blob/dev/src/pdf/CMakeLists.txt Adds synchronization targets for the PDF module and retrieves configuration and architecture lists. It then iterates through these to set up individual GN build targets. ```cmake addSyncTargets(pdf) get_configs(configs) get_architectures(archs) foreach(arch ${archs}) foreach(config ${configs}) ## # BULID.gn SETUP ## set(buildGn pdf_${config}_${arch}) add_gn_target(${buildGn} ${config} ${arch} SOURCES DEFINES CXX_COMPILE_OPTIONS C_COMPILE_OPTIONS INCLUDES MOC_PATH PNG_INCLUDES JPEG_INCLUDES HARFBUZZ_INCLUDES FREETYPE_INCLUDES ZLIB_INCLUDES ) resolve_target_includes(gnIncludes Pdf) get_forward_declaration_macro(forwardDeclarationMacro) extend_gn_target(${buildGn} INCLUDES ${gnIncludes} ) ## # GN PARAMETERS ## unset(gnArgArg) append_build_type_setup(gnArgArg) append_compiler_linker_sdk_setup(gnArgArg) append_sanitizer_setup(gnArgArg) append_toolchain_setup(gnArgArg) append_pkg_config_setup(gnArgArg) list(APPEND gnArgArg qtwebengine_target="${buildDir}/${config}/${arch}:QtPdf" qt_libpng_config="${buildDir}/${config}/${arch}:qt_libpng_config" qt_libjpeg_config="${buildDir}/${config}/${arch}:qt_libjpeg_config" qt_harfbuzz_config="${buildDir}/${config}/${arch}:qt_harfbuzz_config" qt_freetype_config="${buildDir}/${config}/${arch}:qt_freetype_config" is_qtwebengine=true is_qtpdf=true enable_bluetooth_emulation=false enable_swiftshader=false enable_swiftshader_vulkan=false angle_enable_swiftshader=false dawn_use_swiftshader=false use_cups=false use_dawn=false build_dawn_tests=false enable_nocompile_tests=false enable_ipc_fuzzer=false enable_remoting=false enable_resource_allowlist_generation=false enable_vr=false enable_web_speech=false chrome_pgo_phase=0 strip_absolute_paths_from_debug_symbols=false v8_enable_webassembly=false use_v8_context_snapshot=false v8_use_external_startup_data=false build_with_tflite_lib=false webnn_use_tflite=false ) if(LINUX OR ANDROID) list(APPEND gnArgArg enable_vr=false is_cfi=false ozone_auto_platforms=false enable_arcore=false use_ml_inliner=false use_udev=false use_gio=false use_glib=false use_nss_certs=false use_xkbcommon=false v8_use_external_startup_data=false ) extend_gn_list(gnArgArg ARGS use_system_icu CONDITION QT_FEATURE_webengine_system_icu ) extend_gn_list(gnArgArg ARGS use_system_libopenjpeg2 CONDITION QT_FEATURE_webengine_system_libopenjpeg2 ) extend_gn_list(gnArgArg ARGS is_gcc_legacy CONDITION QT_FEATURE_webengine_gcc_legacy_support ) endif() if(MACOS) list(APPEND gnArgArg angle_enable_vulkan=false) endif() if(IOS) list(APPEND gnArgArg enable_base_tracing=false) extend_gn_list(gnArgArg ARGS enable_ios_bitcode CONDITION QT_FEATURE_pdf_bitcode ) endif() if(WIN32 OR ANDROID) list(APPEND gnArgArg safe_browsing_mode=0 ) extend_gn_list(gnArgArg ARGS qt_uses_static_runtime CONDITION QT_FEATURE_pdf_static_runtime ) endif() endforeach() endforeach() ``` -------------------------------- ### Begin SBOM for Qt PDF Project Source: https://github.com/qt/qtwebengine/blob/dev/src/CMakeLists.txt Starts the SBOM generation for the Qt PDF project, specifying the SBOM project name. This is done when the qtpdf feature is enabled. ```cmake if(QT_FEATURE_qtpdf_build) qt_internal_sbom_begin_qt_repo_project(SBOM_PROJECT_NAME QtPdf) ``` -------------------------------- ### Append Build Type Setup to GN Arguments Source: https://github.com/qt/qtwebengine/blob/dev/src/core/CMakeLists.txt Appends build type specific setup to a list of GN arguments. ```cmake unset(gnArgArg) append_build_type_setup(gnArgArg) ``` -------------------------------- ### CMakeLists.txt Configuration for Custom Dialogs Source: https://github.com/qt/qtwebengine/blob/dev/tests/manual/examples/quick/customdialogs/CMakeLists.txt Configures the build system for the custom dialogs example, defining the project, finding necessary Qt components, and setting target properties. ```cmake if (NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) cmake_minimum_required(VERSION 3.16) project(customdialogs LANGUAGES CXX) find_package(Qt6BuildInternals COMPONENTS STANDALONE_TEST) endif() qt_internal_add_manual_test(customdialogs SOURCES main.cpp server.cpp server.h ) set_target_properties(customdialogs PROPERTIES WIN32_EXECUTABLE TRUE MACOSX_BUNDLE TRUE ) target_link_libraries(customdialogs PUBLIC Qt::Core Qt::Gui Qt::WebEngineQuick ) ``` -------------------------------- ### Conditional Installation of GN Toolchain Build Files Source: https://github.com/qt/qtwebengine/blob/dev/src/host/CMakeLists.txt Installs the generated BUILD.gn files for the host and V8 toolchains to specific destinations based on whether qtwebengine or qtpdf builds are enabled. ```cmake if(QT_FEATURE_qtwebengine_build) install(FILES ${buildDir}/host_toolchain/BUILD.gn DESTINATION ${WEBENGINE_ROOT_BUILD_DIR}/src/core/host_toolchain ) install(FILES ${buildDir}/v8_toolchain/BUILD.gn DESTINATION ${WEBENGINE_ROOT_BUILD_DIR}/src/core/v8_toolchain ) endif() if(QT_FEATURE_qtpdf_build) install(FILES ${buildDir}/host_toolchain/BUILD.gn DESTINATION ${WEBENGINE_ROOT_BUILD_DIR}/src/pdf/host_toolchain ) install(FILES ${buildDir}/v8_toolchain/BUILD.gn DESTINATION ${WEBENGINE_ROOT_BUILD_DIR}/src/pdf/v8_toolchain ) endif() ``` -------------------------------- ### CMake Minimum Required and Project Setup Source: https://github.com/qt/qtwebengine/blob/dev/tests/manual/examples/quick/webengineaction/CMakeLists.txt Sets the minimum CMake version and defines the project name and language. This is typically at the beginning of a CMakeLists.txt file. ```cmake cmake_minimum_required(VERSION 3.16) project(webengineaction LANGUAGES CXX) ``` -------------------------------- ### JavaScript Permission Handling Setup Source: https://github.com/qt/qtwebengine/blob/dev/tests/auto/widgets/qwebenginepermission/resources/index.html Sets up global JavaScript variables to manage click state, trigger functions, and store test data for permission-related events. ```javascript var triggerFunc = undefined; var testFunc = undefined; var clicked = false; var done = false; var skipReason = undefined; var data = undefined; function onClick() { clicked = true; triggerFunc(); } ``` -------------------------------- ### Executable and Target Properties Source: https://github.com/qt/qtwebengine/blob/dev/examples/webenginewidgets/notifications/CMakeLists.txt Defines the main executable for the notifications example and sets platform-specific properties for Windows and macOS. ```cmake qt_add_executable(notifications main.cpp notificationpopup.h ) set_target_properties(notifications PROPERTIES WIN32_EXECUTABLE TRUE MACOSX_BUNDLE TRUE ) ``` -------------------------------- ### CMakeLists.txt Configuration for Single Page PDF Example Source: https://github.com/qt/qtwebengine/blob/dev/examples/pdf/singlepage/CMakeLists.txt This CMakeLists.txt file sets up a Qt 6 project for a single-page PDF viewer application. It finds necessary Qt modules, defines the executable, and configures QML resources. ```cmake cmake_minimum_required(VERSION 3.16) project(singlepage LANGUAGES CXX) if(NOT DEFINED INSTALL_EXAMPLESDIR) set(INSTALL_EXAMPLESDIR "examples") endif() set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/pdf/singlepage") find_package(Qt6 REQUIRED COMPONENTS Gui Qml OPTIONAL_COMPONENTS Svg) if(NOT TARGET Qt::Svg) message(WARNING "QtSvg is required as runtime dependency for qtpdfquick examples.") endif() qt_standard_project_setup(REQUIRES 6.8) qt_add_executable(singlepage main.cpp ) qt_add_qml_module(singlepage URI SinglePageModule QML_FILES Viewer.qml RESOURCES resources/document-open.svg resources/edit-clear.svg resources/edit-copy.svg resources/edit-select-all.svg resources/go-down-search.svg resources/go-next-view-page.svg resources/go-previous-view-page.svg resources/go-up-search.svg resources/rotate-left.svg resources/rotate-right.svg resources/zoom-fit-best.svg resources/zoom-fit-width.svg resources/zoom-in.svg resources/zoom-original.svg resources/zoom-out.svg resources/test.pdf ) set_target_properties(singlepage PROPERTIES WIN32_EXECUTABLE TRUE MACOSX_BUNDLE TRUE ) target_link_libraries(singlepage PUBLIC Qt::Gui Qt::Qml ) install(TARGETS singlepage RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) ``` -------------------------------- ### External Project Setup for GN Source: https://github.com/qt/qtwebengine/blob/dev/src/CMakeLists.txt Adds the GN build tool as an external project if it's not already found, especially for cross-compilation scenarios. ```cmake if(NOT Gn_FOUND) qt_webengine_externalproject_add(gn SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/gn BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/gn INSTALL_DIR ${installDir} EXCLUDE_FROM_ALL TRUE ) if(QT_FEATURE_qtwebengine_core_build) add_dependencies(run_core_GnReady gn) endif() if(QT_FEATURE_qtpdf_build) add_dependencies(run_pdf_GnReady gn) endif() endif() ``` -------------------------------- ### Defining the Executable Target Source: https://github.com/qt/qtwebengine/blob/dev/examples/webenginewidgets/maps/CMakeLists.txt Creates the main executable for the maps example, specifying source files. ```cmake qt_add_executable(maps main.cpp mainwindow.cpp mainwindow.h ) ``` -------------------------------- ### Get and Set localStorage Item Source: https://github.com/qt/qtwebengine/blob/dev/tests/auto/quick/qmltests/data/localStorage.html Demonstrates how to retrieve an item from localStorage using getItem and set an item using setItem. Ensure the key is a string. ```javascript document.title = localStorage.getItem('title'); localStorage.setItem('title', 'New Title'); ``` -------------------------------- ### CMake Build Configuration Source: https://github.com/qt/qtwebengine/blob/dev/examples/webenginewidgets/contentmanipulation/CMakeLists.txt Sets up the minimum CMake version, project name, and enables automatic meta-object compilation. It also defines installation directories and finds necessary Qt packages. ```cmake cmake_minimum_required(VERSION 3.16) project(contentmanipulation LANGUAGES CXX) set(CMAKE_AUTOMOC ON) if(NOT DEFINED INSTALL_EXAMPLESDIR) set(INSTALL_EXAMPLESDIR "examples") endif() set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/webenginewidgets/contentmanipulation") find_package(Qt6 REQUIRED COMPONENTS Core Gui WebEngineWidgets) ``` -------------------------------- ### Target Sources and Properties for Framework Builds Source: https://github.com/qt/qtwebengine/blob/dev/src/core/api/CMakeLists.txt When building as a framework (QT_FEATURE_framework is enabled), this section sets the source files for the WebEngineCore target and configures their installation properties, including macOS bundle locations. ```cmake if(QT_FEATURE_framework) set(allResourceFiles ${localeFiles} ${resourceFiles}) target_sources(WebEngineCore PRIVATE ${allResourceFiles}) set_source_files_properties(${localeFiles} TARGET_DIRECTORY WebEngineCore PROPERTIES MACOSX_PACKAGE_LOCATION Resources/qtwebengine_locales GENERATED TRUE ) set_source_files_properties(${resourceFiles} TARGET_DIRECTORY WebEngineCore PROPERTIES MACOSX_PACKAGE_LOCATION Resources GENERATED TRUE ) add_custom_command(OUTPUT ${allResourceFiles} DEPENDS "${stamps}") add_custom_target(generate_resources_${config} DEPENDS ${allResourceFiles}) addCopyCommand(WebEngineCore "${localeFiles}" "${QT_BUILD_DIR}/${INSTALL_LIBDIR}/QtWebEngineCore.framework/Versions/A/Resources/qtwebengine_locales/" ) addCopyCommand(WebEngineCore "${resourceFiles}" "${QT_BUILD_DIR}/${INSTALL_LIBDIR}/QtWebEngineCore.framework/Versions/A/Resources/" ) else() set(locale_install_path "${INSTALL_TRANSLATIONSDIR}/qtwebengine_locales") install(FILES ${localeFiles} DESTINATION ${locale_install_path} CONFIGURATIONS ${config} ) qt_internal_sbom_add_files(WebEngineCore FILES "${localeFiles}" FILE_TYPE "TRANSLATIONS" INSTALL_PATH "${locale_install_path}" ) qt_path_join(resource_install_path "${INSTALL_DATADIR}" "resources") install(FILES ${resourceFiles} DESTINATION ${resource_install_path} CONFIGURATIONS ${config} ) qt_internal_sbom_add_files(WebEngineCore FILES "${resourceFiles}" FILE_TYPE "RESOURCES" INSTALL_PATH "${resource_install_path}" ) if(QT_SUPERBUILD OR NOT QT_WILL_INSTALL) addCopyCommand(WebEngineCore "${localeFiles}" ${QT_BUILD_DIR}/${INSTALL_TRANSLATIONSDIR}/qtwebengine_locales ) addCopyCommand(WebEngineCore "${resourceFiles}" ${QT_BUILD_DIR}/${INSTALL_DATADIR}/resources ) endif() endif() ``` -------------------------------- ### CMake Minimum Requirements and Project Setup Source: https://github.com/qt/qtwebengine/blob/dev/tests/manual/quick/touchbrowser/CMakeLists.txt Sets the minimum CMake version and defines the project name and language. This configuration is applied only when not building standalone tests or the Qt library itself. ```cmake if (NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) cmake_minimum_required(VERSION 3.19) project(touchbrowser LANGUAGES CXX) find_package(Qt6BuildInternals COMPONENTS STANDALONE_TEST) endif() ``` -------------------------------- ### Conditional GN Installation Flag Source: https://github.com/qt/qtwebengine/blob/dev/src/CMakeLists.txt Sets an internal cache variable to indicate if GN should be installed, based on whether it's found or its executable path matches the expected installation path. ```cmake string(REGEX REPLACE "(.)" "\\\\1" path_to_match "${installDir}") if(NOT Gn_FOUND OR Gn_EXECUTABLE MATCHES "^${path_to_match}") set(INSTALL_GN 1 CACHE INTERNAL "") endif() ``` -------------------------------- ### Copy gn Executable for Cross-Build Installation Source: https://github.com/qt/qtwebengine/blob/dev/src/CMakeLists.txt Creates a custom target to copy the 'gn' executable to the build directory when not installing. This ensures the executable is available for cross-compilation builds. ```cmake if((LINUX OR MACOS OR WIN32) AND INSTALL_GN) if(NOT QT_WILL_INSTALL) set(copyOutput ${QT_BUILD_DIR}/${INSTALL_LIBEXECDIR}/gn${CMAKE_EXECUTABLE_SUFFIX} ) if(Gn_FOUND) set(copyInput ${Gn_EXECUTABLE}) set(copyDep ${Gn_EXECUTABLE}) else() set(copyInput ${installDir}/bin/gn${CMAKE_EXECUTABLE_SUFFIX}) set(copyDep gn) endif() add_custom_target(copy-gn ALL DEPENDS ${copyOutput}) add_custom_command( OUTPUT ${copyOutput} COMMAND ${CMAKE_COMMAND} -E copy ${copyInput} ${QT_BUILD_DIR}/${INSTALL_LIBEXECDIR} DEPENDS ${copyDep} USES_TERMINAL ) else() get_install_config(installConfig) install( PROGRAMS "${installDir}/bin/gn${CMAKE_EXECUTABLE_SUFFIX}" CONFIGURATIONS ${installConfig} RUNTIME DESTINATION "${INSTALL_LIBEXECDIR}" ) endif() endif() ``` -------------------------------- ### Configure Qt Quick PDF Module Source: https://github.com/qt/qtwebengine/blob/dev/src/pdfquick/CMakeLists.txt This snippet sets up the PdfQuick QML module, defining its URI, version, QML files, source files, and library dependencies. It's used to build and integrate the PDF viewing capabilities into Qt Quick applications. ```cmake find_package(Qt6 ${PROJECT_VERSION} CONFIG REQUIRED COMPONENTS Core Gui Qml Quick) set(qml_files "+Material/PdfStyle.qml" "+Universal/PdfStyle.qml" "PdfLinkDelegate.qml" "PdfMultiPageView.qml" "PdfPageView.qml" "PdfScrollablePageView.qml" "PdfStyle.qml" ) if(QT_KNOWN_POLICY_QTP0004) qt_policy(SET QTP0004 OLD) endif() qt_internal_add_qml_module(PdfQuick URI "QtQuick.Pdf" VERSION "${PROJECT_VERSION}" PAST_MAJOR_VERSIONS 5 QML_FILES ${qml_files} DEPENDENCIES QtQuick/auto SOURCES qquickpdfbookmarkmodel.cpp qquickpdfbookmarkmodel_p.h qquickpdfdocument.cpp qquickpdfdocument_p.h qquickpdflinkmodel.cpp qquickpdflinkmodel_p.h qquickpdfpagenavigator.cpp qquickpdfpagenavigator_p.h qquickpdfpageimage.cpp qquickpdfpageimage_p.h qquickpdfsearchmodel.cpp qquickpdfsearchmodel_p.h qquickpdfselection.cpp qquickpdfselection_p.h qtpdfquickglobal_p.h INCLUDE_DIRECTORIES ../3rdparty/chromium LIBRARIES Qt::PdfPrivate Qt::QuickPrivate PRIVATE_MODULE_INTERFACE Qt::PdfPrivate Qt::QuickPrivate PUBLIC_LIBRARIES Qt::Core Qt::Gui Qt::Pdf Qt::Qml Qt::Quick NO_GENERATE_CPP_EXPORTS ) ``` -------------------------------- ### Get Notification Permission Source: https://github.com/qt/qtwebengine/blob/dev/tests/auto/httpserver/data/notification.html Retrieves the current permission level for displaying desktop notifications. ```javascript function getPermission() { return Notification.permission } ``` -------------------------------- ### Create Spellchecker Executable Source: https://github.com/qt/qtwebengine/blob/dev/examples/webenginewidgets/spellchecker/CMakeLists.txt Defines the main executable for the spellchecker example, listing its source files. ```cmake qt_add_executable(spellchecker main.cpp webview.cpp webview.h ) ``` -------------------------------- ### Begin SBOM for WebEngine Project Source: https://github.com/qt/qtwebengine/blob/dev/src/CMakeLists.txt Initiates the SBOM process specifically for the WebEngine and WebEngineCore projects. This ensures that components within these modules are correctly accounted for. ```cmake qt_webengine_sbom_project_begin(WebEngine WebEngineCore) ``` -------------------------------- ### Get Textarea Content Source: https://github.com/qt/qtwebengine/blob/dev/tests/auto/widgets/spellchecking/resources/index.html Retrieves the inner HTML content of the first element with the class 'textarea'. ```javascript function text() { return document.getElementsByClassName('textarea')[0].innerHTML; } ``` -------------------------------- ### Basic CMake Configuration for QtWebEngine Process Source: https://github.com/qt/qtwebengine/blob/dev/src/process/CMakeLists.txt Sets up the basic build target for the QtWebEngine process, including source files and include directories. This is a foundational step for building the process. ```cmake # Copyright (C) 2022 The Qt Company Ltd. # SPDX-License-Identifier: BSD-3-Clause if(NOT DEFINED WEBENGINE_ROOT_SOURCE_DIR) qt_internal_get_filename_path_mode(path_mode) get_filename_component(WEBENGINE_ROOT_SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/../.." ${path_mode}) endif() include(${WEBENGINE_ROOT_SOURCE_DIR}/cmake/Functions.cmake) find_package(Qt6 COMPONENTS Gui) get_target_property(qtWebEngineProcessName WebEngineCore QTWEBENGINEPROCESS_NAME) get_target_property(isFramework WebEngineCore FRAMEWORK) if(isFramework) set(install_dir "${INSTALL_LIBDIR}/QtWebEngineCore.framework/Versions/A/Helpers") else() set(install_dir "${INSTALL_LIBEXECDIR}") endif() qt_internal_add_app(${qtWebEngineProcessName} TARGET_DESCRIPTION "QtWebEngine internal process" NO_INSTALL INCLUDE_DIRECTORIES ../core SOURCES main.cpp ) ``` -------------------------------- ### Append Toolchain Setup to GN Arguments Source: https://github.com/qt/qtwebengine/blob/dev/src/core/CMakeLists.txt Appends toolchain specific configurations to a list of GN arguments. ```cmake append_toolchain_setup(gnArgArg) ``` -------------------------------- ### WebSocket Connection and Event Handling Source: https://github.com/qt/qtwebengine/blob/dev/tests/auto/core/origins/resources/websocket2.html Establishes a WebSocket connection using QWebChannel, sends an initial message, and sets up listeners for incoming messages and connection closure. ```javascript var result; new QWebChannel(qt.webChannelTransport, channel => { const ws = new WebSocket(channel.objects.echoServer.url); ws.addEventListener("open", event => { ws.send("ok"); }); ws.addEventListener("message", event => { result = event.data; }); ws.addEventListener("close", event => { result = event.code; }); }) ``` -------------------------------- ### Include Qt Test Macros Source: https://github.com/qt/qtwebengine/blob/dev/tests/auto/cmake/CMakeLists.txt Includes internal Qt test macros to facilitate test setup and execution. ```cmake include("${_Qt6CTestMacros}") ``` -------------------------------- ### Add QtVersion Test Source: https://github.com/qt/qtwebengine/blob/dev/tests/auto/core/qtversion/CMakeLists.txt Configures the tst_qtversion test using CMake, specifying source files and linking against Qt::WebEngineCore. ```cmake # Copyright (C) 2023 The Qt Company Ltd. # SPDX-License-Identifier: BSD-3-Clause dt_internal_add_test(tst_qtversion SOURCES tst_qtversion.cpp LIBRARIES Qt::WebEngineCore ) ``` -------------------------------- ### Get GN Architecture Information Source: https://github.com/qt/qtwebengine/blob/dev/src/host/CMakeLists.txt Retrieves architecture information for the target, host, and V8 builds using helper functions. ```cmake get_gn_arch(target_arch ${GN_TARGET_CPU}) get_gn_arch(host_arch ${TEST_architecture_arch}) get_v8_arch(v8_arch ${target_arch} ${host_arch}) ``` -------------------------------- ### Begin SBOM for PDF Project Source: https://github.com/qt/qtwebengine/blob/dev/src/CMakeLists.txt Initiates the SBOM process specifically for the Pdf and Pdf components. This ensures that components within these modules are correctly accounted for. ```cmake qt_webengine_sbom_project_begin(Pdf Pdf) ``` -------------------------------- ### Configure and Run CMake Script Source: https://github.com/qt/qtwebengine/blob/dev/src/CMakeLists.txt Initiates the configuration process and runs a specific CMake script for WebEngine. This step is crucial for setting up build variables and dependencies. ```cmake qt_webengine_configure_begin() qt_webengine_run_configure("../configure.cmake") ``` -------------------------------- ### Get Shared Data Path Source: https://github.com/qt/qtwebengine/blob/dev/tests/auto/widgets/loadsignals/CMakeLists.txt Retrieves the SHARED_DATA property from the Test::HttpServer target. This path is used to locate test resource files. ```cmake get_target_property(sharedData Test::HttpServer SHARED_DATA) ``` -------------------------------- ### Configure QtWebEngine Dictionary Conversion Tool Source: https://github.com/qt/qtwebengine/blob/dev/src/core/tools/qwebengine_convert_dict/CMakeLists.txt Sets up the build for the qwebengine_convert_dict tool, enabling specific features and compiler options based on the build environment. ```cmake if(QT_FEATURE_webengine_spellchecker AND NOT CMAKE_CROSSCOMPILING) qt_get_tool_target_name(dict_target_name qwebengine_convert_dict) qt_internal_add_tool(${dict_target_name} TARGET_DESCRIPTION "QtWebEngine Dictionary Conversion Tool" INSTALL_DIR ${INSTALL_LIBEXECDIR} TOOLS_TARGET WebEngineCore DEFINES TOOLKIT_QT SOURCES main.cpp INCLUDE_DIRECTORIES ../../../3rdparty/chromium/third_party/abseil-cpp ) if(MSVC AND NOT CLANG) target_compile_options(${dict_target_name} PRIVATE "/Zc:preprocessor") endif() if(COMMAND qt_internal_return_unless_building_tools) qt_internal_return_unless_building_tools() endif() qt_skip_warnings_are_errors(${dict_target_name}) add_dependencies(${dict_target_name} WebEngineCore) qt_internal_extend_target(${dict_target_name} CONDITION WIN32 DEFINES WIN32_LEAN_AND_MEAN ) qt_internal_extend_target(${dict_target_name} CONDITION GCC OR CLANG COMPILE_OPTIONS -Wno-unused-parameter ) set_target_properties(${dict_target_name} PROPERTIES CXX_STANDARD 20) if(NOT QT_FEATURE_webengine_system_icu AND QT_WILL_INSTALL) # tool can be called durig build so copy icu file get_target_property(icuFile WebEngineCore ICUDTL_FILE) addCopyCommand(${dict_target_name} "${icuFile}" "${QT_BUILD_DIR}/${INSTALL_LIBEXECDIR}") endif() qt_internal_extend_target(${dict_target_name} CONDITION NOT QT_FEATURE_webengine_system_icu DEFINES USE_ICU_FILE ) endif() ``` -------------------------------- ### JavaScript Get Pressed Modifiers Function Source: https://github.com/qt/qtwebengine/blob/dev/tests/auto/quick/qmltests/data/keyboardModifierMapping.html A helper function to retrieve the current text content indicating the state of Alt, Ctrl, and Meta modifiers. ```javascript function getPressedModifiers() { return "alt:" + alt_state.textContent + " ctrl:" + ctrl_state.textContent + " meta:" + meta_state.textContent } ``` -------------------------------- ### Generate WebEngine Platform Notes Documentation Source: https://github.com/qt/qtwebengine/blob/dev/src/CMakeLists.txt Generates platform-specific documentation for Qt WebEngine. This uses a QDoc input file to create an output documentation file. ```cmake qt_webengine_generate_documentation( core/doc/src/qtwebengine-platform-notes.qdoc.in core/api/qtwebengine-platform-notes.qdoc ) ``` -------------------------------- ### Add WebEngine Quick Subdirectory Source: https://github.com/qt/qtwebengine/blob/dev/src/CMakeLists.txt Includes the 'webenginequick' subdirectory for building Qt WebEngine's Quick components. This is conditional on the qtwebengine_quick feature being enabled. ```cmake if(QT_FEATURE_qtwebengine_quick_build) add_subdirectory(webenginequick) ``` -------------------------------- ### Show Directory Picker and Iterate Entries Source: https://github.com/qt/qtwebengine/blob/dev/tests/auto/quick/qmltests/data/filesystemapi.html Use `window.showDirectoryPicker()` to allow the user to select a directory. The `values()` method returns an async iterator that can be used to loop through the directory's entries. Each entry's `kind` property indicates whether it is a 'file' or 'directory'. ```javascript console.log("start") const dirHandle = await window.showDirectoryPicker(); for await (const entry of dirHandle.values()) { if (entry.kind === "file"){ continue } if (entry.kind === "directory") { console.log("TEST:" + entry.name) } } console.log("TEST:DONE") ``` -------------------------------- ### Creating C++ Configurations for PDF Source: https://github.com/qt/qtwebengine/blob/dev/src/pdf/CMakeLists.txt After setting up GN arguments and commands, create C++ configurations for the PDF target using create_cxx_configs. This is typically done within a loop iterating over architectures. ```cmake create_cxx_configs(Pdf ${arch}) ``` -------------------------------- ### Get WebEngine Root Directories Source: https://github.com/qt/qtwebengine/blob/dev/src/CMakeLists.txt Determines the root source and build directories for the WebEngine project. This is essential for locating project files and setting up build paths. ```cmake qt_internal_get_filename_path_mode(path_mode) get_filename_component(WEBENGINE_ROOT_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/.." ${path_mode}) get_filename_component(WEBENGINE_ROOT_BUILD_DIR "${PROJECT_BINARY_DIR}" ${path_mode}) ``` -------------------------------- ### Define QML Files for Module Source: https://github.com/qt/qtwebengine/blob/dev/src/webenginequick/ui/CMakeLists.txt Lists all QML files to be included in the WebEngineQuickDelegatesQml module. Ensure all necessary QML components are listed here. ```cmake set(qml_files "AlertDialog.qml" "AuthenticationDialog.qml" "AutofillPopup.qml" "ConfirmDialog.qml" "DirectoryPicker.qml" "FilePicker.qml" "Menu.qml" "MenuItem.qml" "MenuSeparator.qml" "PromptDialog.qml" "ToolTip.qml" "TouchHandle.qml" "TouchSelectionMenu.qml" ${colorDialog} ) ``` -------------------------------- ### JavaScript for QWebChannel Integration Source: https://github.com/qt/qtwebengine/blob/dev/examples/webenginewidgets/recipebrowser/assets/pages/soup.html This JavaScript code sets up a QWebChannel connection to communicate with the Qt backend. It retrieves the initial HTML content, establishes a connection, and sets up a listener to update the content whenever it changes. ```javascript 'use strict'; var jsContent = document.getElementById('content'); var placeholder = document.getElementById('placeholder'); var updateText = function(text) { placeholder.innerHTML = marked.parse(text); } new QWebChannel(qt.webChannelTransport, function(channel) { var content = channel.objects.content; content.setInitialText(jsContent.innerHTML); content.textChanged.connect(updateText); } ); ``` -------------------------------- ### Find Required Packages Source: https://github.com/qt/qtwebengine/blob/dev/src/core/CMakeLists.txt Ensures that Ninja, Nodejs, and Perl are available for the build. PkgConfig is optionally found and used to create a host wrapper if available. ```cmake find_package(Ninja ${QT_CONFIGURE_CHECK_ninja_version} REQUIRED) find_package(Nodejs ${QT_CONFIGURE_CHECK_nodejs_version} REQUIRED) find_package(Perl) find_package(PkgConfig) if(PkgConfig_FOUND) create_pkg_config_host_wrapper(${CMAKE_CURRENT_BINARY_DIR}) endif() ``` -------------------------------- ### CMakeLists.txt Configuration for Qt WebEngine Source: https://github.com/qt/qtwebengine/blob/dev/tests/manual/examples/quick/minimal/CMakeLists.txt This snippet shows the essential CMake configuration for a minimal Qt WebEngine application. It sets up the project, finds necessary Qt modules, and defines the target executable. ```cmake cmake_minimum_required(VERSION 3.16) project(minimal LANGUAGES CXX) find_package(Qt6BuildInternals COMPONENTS STANDALONE_TEST) ``` ```cmake qt_internal_add_manual_test(webengine-minimal-qml SOURCES main.cpp ) ``` ```cmake set_target_properties(webengine-minimal-qml PROPERTIES WIN32_EXECUTABLE TRUE MACOSX_BUNDLE TRUE ) ``` ```cmake target_link_libraries(webengine-minimal-qml PUBLIC Qt::Core Qt::Gui Qt::WebEngineQuick ) ``` ```cmake set(qml_resource_files "main.qml" ) qt_add_resources(webengine-minimal-qml "qml" PREFIX "/" FILES ${qml_resource_files} ) ``` -------------------------------- ### CMakeLists.txt for Qt WebGL Tests Source: https://github.com/qt/qtwebengine/blob/dev/tests/manual/widgets/webgl/CMakeLists.txt Configures the build for Qt WebGL standalone tests. It sets up the project, finds necessary Qt components, and defines the test executable. ```cmake if (NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) cmake_minimum_required(VERSION 3.16) project(webgl LANGUAGES CXX) find_package(Qt6BuildInternals COMPONENTS STANDALONE_TEST) endif() qt_internal_add_manual_test(webgl GUI SOURCES main.cpp LIBRARIES Qt::Core Qt::Gui Qt::WebEngineWidgets ENABLE_AUTOGEN_TOOLS moc ) ``` -------------------------------- ### Qt Internal Manual Test Configuration Source: https://github.com/qt/qtwebengine/blob/dev/tests/manual/quick/touchbrowser/CMakeLists.txt Configures a manual test target named 'touchbrowser-quick' for the GUI. It specifies source files, required Qt libraries, and enables automatic code generation tools like moc. ```cmake qt_internal_add_manual_test(touchbrowser-quick GUI SOURCES main.cpp resources.qrc ${TOUCHMOCKING_DIR}/touchmockingapplication.cpp ${TOUCHMOCKING_DIR}/touchmockingapplication.h ${TOUCHMOCKING_DIR}/utils.h LIBRARIES Qt::Core Qt::Quick Qt::WebEngineQuick ENABLE_AUTOGEN_TOOLS moc ) ``` -------------------------------- ### Add Test Case Configuration Source: https://github.com/qt/qtwebengine/blob/dev/tests/auto/quick/qquickwebenginedefaultsurfaceformat/CMakeLists.txt Configures the tst_qquickwebenginedefaultsurfaceformat test case using CMake. Specifies source files and necessary libraries for the test. ```cmake # Copyright (C) 2022 The Qt Company Ltd. # SPDX-License-Identifier: BSD-3-Clause include(../../util/util.cmake) qt_internal_add_test(tst_qquickwebenginedefaultsurfaceformat SOURCES tst_qquickwebenginedefaultsurfaceformat.cpp LIBRARIES Qt::CorePrivate Qt::WebEngineQuickPrivate Test::Util ) ``` -------------------------------- ### Send XHR with Load and Error Listeners Source: https://github.com/qt/qtwebengine/blob/dev/tests/auto/core/origins/resources/mixedXHR.html This snippet sends a GET request and sets up listeners for both successful loading and network errors. The result is stored in a global 'result' variable. ```javascript var result; function sendXHR(url) { result = undefined; let req = new XMLHttpRequest(); req.addEventListener("load", () => { result = req.responseText; }); req.addEventListener("error", () => { result = "error"; }); req.open("GET", url); req.send(); } ```