当前位置: 首页 > news >正文

Qt系列:调用Edge浏览器示例

背景

需要解决以下几个问题

  1. 政府项目新浏览器兼容老系统ActiveX控件,Qt WebEngineView没有直接的实现方案,需要利用Qt的ActiveX兼容模块与浏览器往返多次交互
  2. Qt ActiveX未实现COM事件通知
  3. 官方Win32示例存在滥用lambda函数的嫌疑,lambda函数多层嵌套,程序逻辑层次混乱,整个逻辑被揉成一垛。

官方示例代码

官方介绍文档在这里:https://learn.microsoft.com/microsoft-edge/webview2/get-started/win32。官方代码仓库在这里:GitHub - MicrosoftEdge/WebView2Samples: Microsoft Edge WebView2 samples

摘录一段lambda多层嵌套的代码,你们体会一下:

	CreateCoreWebView2EnvironmentWithOptions(nullptr, nullptr, nullptr,Callback<ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler>([hWnd](HRESULT result, ICoreWebView2Environment* env) -> HRESULT {// Create a CoreWebView2Controller and get the associated CoreWebView2 whose parent is the main window hWndenv->CreateCoreWebView2Controller(hWnd, Callback<ICoreWebView2CreateCoreWebView2ControllerCompletedHandler>([hWnd](HRESULT result, ICoreWebView2Controller* controller) -> HRESULT {if (controller != nullptr) {webviewController = controller;webviewController->get_CoreWebView2(&webview);}// Add a few settings for the webview// The demo step is redundant since the values are the default settingswil::com_ptr<ICoreWebView2Settings> settings;webview->get_Settings(&settings);settings->put_IsScriptEnabled(TRUE);settings->put_AreDefaultScriptDialogsEnabled(TRUE);settings->put_IsWebMessageEnabled(TRUE);// Resize WebView to fit the bounds of the parent windowRECT bounds;GetClientRect(hWnd, &bounds);webviewController->put_Bounds(bounds);// Schedule an async task to navigate to Bingwebview->Navigate(L"https://www.bing.com/");// <NavigationEvents>// Step 4 - Navigation events// register an ICoreWebView2NavigationStartingEventHandler to cancel any non-https navigationEventRegistrationToken token;webview->add_NavigationStarting(Callback<ICoreWebView2NavigationStartingEventHandler>([](ICoreWebView2* webview, ICoreWebView2NavigationStartingEventArgs* args) -> HRESULT {wil::unique_cotaskmem_string uri;args->get_Uri(&uri);std::wstring source(uri.get());if (source.substr(0, 5) != L"https") {args->put_Cancel(true);}return S_OK;}).Get(), &token);// </NavigationEvents>// <Scripting>// Step 5 - Scripting// Schedule an async task to add initialization script that freezes the Object objectwebview->AddScriptToExecuteOnDocumentCreated(L"Object.freeze(Object);", nullptr);// Schedule an async task to get the document URLwebview->ExecuteScript(L"window.document.URL;", Callback<ICoreWebView2ExecuteScriptCompletedHandler>([](HRESULT errorCode, LPCWSTR resultObjectAsJson) -> HRESULT {LPCWSTR URL = resultObjectAsJson;//doSomethingWithURL(URL);return S_OK;}).Get());// </Scripting>// <CommunicationHostWeb>// Step 6 - Communication between host and web content// Set an event handler for the host to return received message back to the web contentwebview->add_WebMessageReceived(Callback<ICoreWebView2WebMessageReceivedEventHandler>([](ICoreWebView2* webview, ICoreWebView2WebMessageReceivedEventArgs* args) -> HRESULT {wil::unique_cotaskmem_string message;args->TryGetWebMessageAsString(&message);// processMessage(&message);webview->PostWebMessageAsString(message.get());return S_OK;}).Get(), &token);// Schedule an async task to add initialization script that// 1) Add an listener to print message from the host// 2) Post document URL to the hostwebview->AddScriptToExecuteOnDocumentCreated(L"window.chrome.webview.addEventListener(\'message\', event => alert(event.data));" \L"window.chrome.webview.postMessage(window.document.URL);",nullptr);// </CommunicationHostWeb>return S_OK;}).Get());return S_OK;}).Get());

解决方案

下面以实现自动登录外网网关为目标,企业微信自动上线,免开机输入账号密码。这样领导看到你上线,可以开机以后就可以慢慢吃早餐了。(开个玩笑)

本实现方案把官方示例代码做成了静态库,没有添加其它东西。

新建CMake项目

这里用到了Qt5静态库,目的是单文件可执行,不需要部署。需要静态库的读者可以自行删除。代码如下:

cmake_minimum_required(VERSION 3.21)
project(auto-online CXX)set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOMOC ON)add_definitions(/D_UNICODE /DUNICODE)
add_compile_definitions(WIN32 _WINDOWS)add_compile_options(/utf-8 $<IF:$<CONFIG:Debug>,/MTd,/MT>)
link_directories($ENV{Qt5_DIR}/lib)
link_directories($ENV{Qt5_DIR}/plugins/platforms)
link_directories($ENV{Qt5_DIR}/plugins/imageformats)
link_libraries(UxTheme Winmm Version ws2_32 imm32 dwmapi)link_libraries($<IF:$<CONFIG:Debug>,Qt5FontDatabaseSupportd,Qt5FontDatabaseSupport>)
link_libraries($<IF:$<CONFIG:Debug>,Qt5UiToolsd,Qt5UiTools>)
link_libraries($<IF:$<CONFIG:Debug>,Qt5AccessibilitySupportd,Qt5AccessibilitySupport>)
link_libraries($<IF:$<CONFIG:Debug>,Qt5EventDispatcherSupportd,Qt5EventDispatcherSupport>)
link_libraries($<IF:$<CONFIG:Debug>,Qt5ThemeSupportd,Qt5ThemeSupport>)
link_libraries($<IF:$<CONFIG:Debug>,Qt5UiToolsd,Qt5UiTools>)link_libraries($<IF:$<CONFIG:Debug>,qtpcre2d,qtpcre2>)
link_libraries($<IF:$<CONFIG:Debug>,qtlibpngd,qtlibpng>)
link_libraries($<IF:$<CONFIG:Debug>,qtharfbuzzd,qtharfbuzz>)
link_libraries($<IF:$<CONFIG:Debug>,qtfreetyped,qtfreetype>)
link_libraries($<IF:$<CONFIG:Debug>,qwindowsd,qwindows>)
link_libraries($<IF:$<CONFIG:Debug>,qicnsd,qicns>)
link_libraries($<IF:$<CONFIG:Debug>,qtgad,qtga>)
link_libraries($<IF:$<CONFIG:Debug>,qtiffd,qtiff>)
link_libraries($<IF:$<CONFIG:Debug>,qwbmpd,qwbmp>)
link_libraries($<IF:$<CONFIG:Debug>,qtiffd,qtiff>)
link_libraries($<IF:$<CONFIG:Debug>,qwebpd,qwebp>)
link_libraries($<IF:$<CONFIG:Debug>,qgifd,qgif>)
link_libraries($<IF:$<CONFIG:Debug>,qjpegd,qjpeg>)
link_libraries($<IF:$<CONFIG:Debug>,qicod,qico>)message("-- Qt5_DIR: " $ENV{Qt5_DIR})
find_package(Qt5 COMPONENTS Core Gui Widgets Network REQUIRED)include_directories(${CMAKE_SOURCE_DIR}/3rdparty/webview2loader/include)
include_directories(${CMAKE_SOURCE_DIR}/3rdparty/wil/include)
link_directories(${CMAKE_SOURCE_DIR}/3rdparty/webview2loader/lib)
link_libraries(Qt5::Core Qt5::Gui Qt5::Widgets Qt5::Network WebView2LoaderStatic)file(GLOB SRCS *.ui *.cpp *.h)
add_executable(${PROJECT_NAME} WIN32 ${SRCS})
set_directory_properties(PROPERTIES VS_STARTUP_PROJECT ${PROJECT_NAME})
# 环境变量的路径不能带双引号
# message("VCINSTALLDIR: " $ENV{VCINSTALLDIR})
# find_file(VSPATH NAMES "vcruntime140d.dll" PATHS $ENV{VCINSTALLDIR}  REQUIRED NO_DEFAULT_PATH)
# file(TO_NATIVE_PATH ${VSPATH} VSPATH) 
#message("VC CRT PATH: " ${VSPATH})
# set(VSPATH $<IF:$<CONFIG:Debug>,$ENV{VCINSTALLDIR}/Redist/MSVC/14.29.30133/onecore/debug_nonredist/x64/Microsoft.VC142.DebugCRT,$ENV{VCINSTALLDIR}/Redist/MSVC/14.29.30133/x64/Microsoft.VC142.CRT> CACHE STRING "VCRT" FORCE)
# string(CONCAT VSPATH ${VSPATH} ";$ENV{Qt5_DIR}\\bin")set_target_properties(${PROJECT_NAME} PROPERTIESVS_DEBUGGER_WORKING_DIRECTORY ${CMAKE_BINARY_DIR}VS_DEBUGGER_ENVIRONMENT "Path=$ENV{Qt5_DIR}\\bin"WIN32_EXECUTABLE TRUE)

用Qt Designer设计一个简单的窗口类型

类型名字很简单,就是MainWindow。这个窗口仅启用了布局,没有添加任何控件。UI代码如下:

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0"><class>MainWindow</class><widget class="QMainWindow" name="MainWindow"><property name="geometry"><rect><x>0</x><y>0</y><width>800</width><height>600</height></rect></property><property name="windowTitle"><string>MainWindow</string></property><widget class="QWidget" name="central_widget"><layout class="QVBoxLayout" name="vl1"><property name="spacing"><number>0</number></property><property name="leftMargin"><number>0</number></property><property name="topMargin"><number>0</number></property><property name="rightMargin"><number>0</number></property><property name="bottomMargin"><number>0</number></property><item><widget class="QWidget" name="browser_widget" native="true"><layout class="QVBoxLayout" name="vl2"/></widget></item></layout></widget></widget><resources/><connections/>
</ui>

声明信号槽

#ifndef MAINWINDOW_H
#define MAINWINDOW_H#include <QMainWindow>
#include <QThread>#include <windows.h>
#include <stdlib.h>
#include <string>
#include <tchar.h>
#include "wrl.h"
#include "wil/com.h"
#include "WebView2.h"#define PROFILE_DATA "cw_webview2"namespace Ui {
class MainWindow;
}class MainWindow : public QMainWindow
{Q_OBJECTpublic:explicit MainWindow(QWidget *parent = nullptr);~MainWindow();void load_webview2(HWND hWnd);void task_run();HRESULT cb_create_environment(HWND, HRESULT, ICoreWebView2Environment *);HRESULT cb_create_controller(HWND, HRESULT, ICoreWebView2Controller *);HRESULT on_navigate_started(ICoreWebView2 *, ICoreWebView2NavigationStartingEventArgs *);HRESULT cb_execute_script(HRESULT, LPCWSTR);HRESULT on_webmessage_received(ICoreWebView2 *, ICoreWebView2WebMessageReceivedEventArgs *);HRESULT on_navigate_completed(ICoreWebView2*, ICoreWebView2NavigationCompletedEventArgs*);// HRESULT cb_deliver(HWND, HRESULT, ...);signals:void prepare();void load_auth_page();void put_name();void put_password();void click_login();void wait(int iminute);protected:void resizeEvent(QResizeEvent* evt) override;void closeEvent(QCloseEvent*) override;protected slots:void on_prepare();void on_load_auth_page();void on_put_name();void on_put_password();void on_click_login();void on_wait(int iminute);private:Ui::MainWindow *ui;// Pointer to WebViewControllerwil::com_ptr<ICoreWebView2Controller> m_controller;bool m_brunning = false;QThread* m_task;// Pointer to WebView windowwil::com_ptr<ICoreWebView2_15> m_webview;Microsoft::WRL::ComPtr<ICoreWebView2ExecuteScriptCompletedHandler> js_cb;Microsoft::WRL::ComPtr<ICoreWebView2WebMessageReceivedEventHandler> msg_cb;
};#endif // MAINWINDOW_H

在合适的时机填入账号密码

本来想做成弹框让用户输入账号密码,忽然发现这种做法对信息部门的同事不太友好,各位读者如有请自行修改。示例代码中的网关地址、用户名和密码是乱写的。

#include "MainWindow.h"
#include "ui_MainWindow.h"#include <QResizeEvent>
#include <QRect>
#include <QDebug>
#include <QStandardPaths>
#include <QDir>
#include <QMessageBox>
#include <QTimer>
#include <QApplication>using namespace Microsoft::WRL;MainWindow::MainWindow(QWidget *parent) :QMainWindow(parent),ui(new Ui::MainWindow)
{ui->setupUi(this);load_webview2((HWND)ui->browser_widget->winId());setWindowTitle(u8"自动连接外网工具");connect(this, SIGNAL(prepare()), this, SLOT(on_prepare()), Qt::QueuedConnection);connect(this, SIGNAL(load_auth_page()), this, SLOT(on_load_auth_page()), Qt::QueuedConnection);connect(this, SIGNAL(put_name()), this, SLOT(on_put_name()), Qt::QueuedConnection);connect(this, SIGNAL(put_password()), this, SLOT(on_put_password()), Qt::QueuedConnection);connect(this, SIGNAL(click_login()), this, SLOT(on_click_login()), Qt::QueuedConnection);connect(this, SIGNAL(wait(int)), this, SLOT(on_wait(int)), Qt::QueuedConnection);
}MainWindow::~MainWindow()
{delete ui;
}HRESULT MainWindow::on_navigate_started(ICoreWebView2 *webview,ICoreWebView2NavigationStartingEventArgs *args)
{wil::unique_cotaskmem_string uri;args->get_Uri(&uri);QString zurl = QString::fromStdWString(uri.get());// std::wstring source(uri.get());// if (source.substr(0, 5) != L"https")// {//     args->put_Cancel(true);// }qInfo().noquote() << "navigate: " << zurl;return S_OK;
}HRESULT MainWindow::cb_execute_script(HRESULT errorCode, LPCWSTR resultObjectAsJson)
{LPCWSTR URL = resultObjectAsJson;//doSomethingWithURL(URL);qInfo() << "executed javascript.";return S_OK;
}HRESULT MainWindow::on_webmessage_received(ICoreWebView2 *webview,ICoreWebView2WebMessageReceivedEventArgs *args)
{wil::unique_cotaskmem_string message;args->TryGetWebMessageAsString(&message);// processMessage(&message);//webview->PostWebMessageAsString(message.get());QString zmsg = QString::fromStdWString(message.get());qInfo().noquote() << "message: " << zmsg;return S_OK;
}HRESULT MainWindow::on_navigate_completed(ICoreWebView2 *webview,ICoreWebView2NavigationCompletedEventArgs *args)
{BOOL bsuccess;COREWEBVIEW2_WEB_ERROR_STATUS ierror;args->get_IsSuccess(&bsuccess);args->get_WebErrorStatus(&ierror);LPWSTR lpuri;webview->get_Source(&lpuri);QString zuri = QString::fromStdWString(lpuri);qInfo().noquote() << "complate : " << bsuccess << ", " << ierror << ", " << zuri;return S_OK;
}void MainWindow::resizeEvent(QResizeEvent *evt)
{if (!m_controller)return;RECT rc;QRect qrc =  ui->browser_widget->rect();rc.left = qrc.left();rc.top = qrc.top();rc.right = qrc.right();rc.bottom = qrc.bottom();m_controller->put_Bounds(rc);
}void MainWindow::closeEvent(QCloseEvent *)
{m_brunning = false;m_task->terminate();QThread::sleep(1);m_task->deleteLater();m_task = nullptr;
}void MainWindow::on_prepare()
{if (!m_webview)return;m_webview->NavigateToString(L"Preparing...");
}void MainWindow::on_load_auth_page()
{if (!m_webview)return;m_webview->Navigate(L"http://1.1.1.3/ac_portal/default/pc.html?tabs=pwd");qInfo() << "begin load auth page";
}void MainWindow::on_put_name()
{if (!m_webview)return;m_webview->ExecuteScript(L"$('#password_name').val('test1');""window.chrome.webview.postMessage('put name ok.');",js_cb.Get());
}void MainWindow::on_put_password()
{if (!m_webview)return;m_webview->ExecuteScript(L"$('#password_pwd').val('123456');""window.chrome.webview.postMessage('put password ok.');",js_cb.Get());
}void MainWindow::on_click_login()
{if (!m_webview)return;m_webview->ExecuteScript(L"$('#password_submitBtn').click();""window.chrome.webview.postMessage('click login ok.');",js_cb.Get());
}void MainWindow::on_wait(int iminute)
{QString zhtml = QString("Already wairted %1 minutes.").arg(iminute);if (!m_webview)return;m_webview->NavigateToString(zhtml.toStdWString().c_str());
}HRESULT MainWindow::cb_create_controller(HWND hWnd, HRESULT result,ICoreWebView2Controller *controller)
{if (!controller)return E_POINTER;m_controller = controller;wil::com_ptr<ICoreWebView2> webview;HRESULT ir =  m_controller->get_CoreWebView2(&webview);if (FAILED(ir))return ir;ir = webview->QueryInterface(IID_ICoreWebView2_15, (void **)&m_webview);if (FAILED(ir))return ir;// Add a few settings for the webview// The demo step is redundant since the values are the default settingswil::com_ptr<ICoreWebView2Settings> settings;m_webview->get_Settings(&settings);settings->put_IsScriptEnabled(TRUE);settings->put_AreDefaultScriptDialogsEnabled(TRUE);settings->put_IsWebMessageEnabled(TRUE);// Resize WebView to fit the bounds of the parent windowRECT bounds;GetClientRect(hWnd, &bounds);m_controller->put_Bounds(bounds);m_webview->NavigateToString(L"Preparing...");// <NavigationEvents>// Step 4 - Navigation events// register an ICoreWebView2NavigationStartingEventHandler to cancel any non-https navigationEventRegistrationToken token;auto nav_func = std::bind(&MainWindow::on_navigate_started, this, std::placeholders::_1,std::placeholders::_2);auto nav_cb = Callback<ICoreWebView2NavigationStartingEventHandler>(nav_func);m_webview->add_NavigationStarting(nav_cb.Get(), &token);auto com_func = std::bind(&MainWindow::on_navigate_completed, this, std::placeholders::_1,std::placeholders::_2);auto com_cb = Callback<ICoreWebView2NavigationCompletedEventHandler>(com_func);m_webview->add_NavigationCompleted(com_cb.Get(), &token);// </NavigationEvents>// <Scripting>// Step 5 - Scripting// Schedule an async task to add initialization script that freezes the Object object// 注入脚本//webview->AddScriptToExecuteOnDocumentCreated(L"Object.freeze(Object);", nullptr);// Schedule an async task to get the document URLauto js_func = std::bind(&MainWindow::cb_execute_script, this, std::placeholders::_1,std::placeholders::_2);js_cb = Callback<ICoreWebView2ExecuteScriptCompletedHandler>(js_func);//webview->ExecuteScript(L"window.document.URL;", js_cb.Get());// </Scripting>// <CommunicationHostWeb>// Step 6 - Communication between host and web content// Set an event handler for the host to return received message back to the web contentauto msg_func = std::bind(&MainWindow::on_webmessage_received, this, std::placeholders::_1,std::placeholders::_2);msg_cb = Callback<ICoreWebView2WebMessageReceivedEventHandler>(msg_func);m_webview->add_WebMessageReceived(msg_cb.Get(), &token);// Schedule an async task to add initialization script that// 1) Add an listener to print message from the host// 2) Post document URL to the host// 注入脚本//webview->AddScriptToExecuteOnDocumentCreated(//    L"window.chrome.webview.addEventListener(\'message\', event => alert(event.data));" \//    L"window.chrome.webview.postMessage(window.document.URL);",//    nullptr);// </CommunicationHostWeb>m_task = QThread::create(&MainWindow::task_run, this);m_task->setParent(this);m_task->start();return S_OK;
}void MainWindow::load_webview2(HWND hWnd)
{MainWindow *obj = this;auto func = &MainWindow::cb_create_environment;auto fn = [hWnd, obj, func](HRESULT result, ICoreWebView2Environment * env)->HRESULT{return (obj->*func)(hWnd, result, env);};auto cb = Callback<ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler>(fn);QDir d(QStandardPaths::writableLocation(QStandardPaths::TempLocation));auto ztemp = d.absoluteFilePath(PROFILE_DATA).toStdWString();HRESULT ir = CreateCoreWebView2EnvironmentWithOptions(nullptr, ztemp.c_str(), nullptr, cb.Get());if (FAILED(ir)){qCritical() << "create webview2 failed. code: " << ir;QTimer::singleShot(3000, [](){QApplication::quit();_Exit(1);});QMessageBox::warning(this,windowTitle(),u8"严重错误。程序即将退出。\n""请检查Microsoft Edge WebView2 Runtime是否存在。\n");}
}void MainWindow::task_run()
{if (!m_controller || !m_webview)return;m_brunning = true;while (m_brunning){emit on_prepare();QThread::sleep(3);if (!m_brunning)break;emit load_auth_page();QThread::sleep(10);if (!m_brunning)break;emit put_name();QThread::sleep(3);if (!m_brunning)break;emit put_password();QThread::sleep(3);if (!m_brunning)break;emit click_login();for (int i = 0; i < 10; i++){QThread::sleep(60);if (!m_brunning)break;emit wait(i + 1);}}
}HRESULT MainWindow::cb_create_environment(HWND hWnd, HRESULT result, ICoreWebView2Environment *env)
{MainWindow *obj = this;auto func = &MainWindow::cb_create_controller;auto fn = [hWnd, obj, func](HRESULT result, ICoreWebView2Controller * controller)->HRESULT{return (obj->*func)(hWnd, result, controller);};// Create a CoreWebView2Controller and get the associated CoreWebView2 whose parent is the main window hWndauto cb = Callback<ICoreWebView2CreateCoreWebView2ControllerCompletedHandler>(fn);HRESULT hr = env->CreateCoreWebView2Controller(hWnd, cb.Get());return hr;
}

免责声明

此代码仅供技术研究娱乐之用,禁止用于商业用途,否则一切后果自负。

作者:岬淢箫声

岬淢箫声的博客_CSDN博客-C/C++,MFC/VC,桌面H5领域博主icon-default.png?t=N176https://caowei.blog.csdn.net/

转载请注明来源

相关文章:

Qt系列:调用Edge浏览器示例

背景 需要解决以下几个问题 政府项目新浏览器兼容老系统ActiveX控件&#xff0c;Qt WebEngineView没有直接的实现方案&#xff0c;需要利用Qt的ActiveX兼容模块与浏览器往返多次交互Qt ActiveX未实现COM事件通知官方Win32示例存在滥用lambda函数的嫌疑&#xff0c;lambda函数…...

内推|香港外企急招ETL工程师!数据分析师+Python开发+运营专家

2月已过半还在找工作&#xff1f;快来看看有没有适合你的岗位&#xff01;01公司&#xff1a;友邦科技 工作地点&#xff1a;成都市高新区OCG国际中心招聘岗位&#xff1a;ETL工程师 15-18k该岗位为香港项目&#xff0c;需要有数仓或者大数据经验。本科IT或数据相关专业&#…...

zlib压缩原理

数据压缩的本质 去除数据中的冗余信息&#xff0c;对于ABABABABABABAB字样的字符串&#xff0c;AB出现了7次&#xff0c;占用14个字节&#xff0c;如果将该字符串编码为7AB&#xff0c;只占用3个字节。 为什么需要对数据压缩 数据需要存储或者传输&#xff0c;为了节省磁盘空…...

论文阅读笔记《DEEP GRAPH MATCHING CONSENSUS》

核心思想 本文提出一种基于图神经网络的图匹配方法&#xff0c;首先利用节点相似度构建初始的匹配关系&#xff0c;然后利用局部的一致性对初始的匹配关系进行迭代优化&#xff0c;不断筛除误匹配点&#xff0c;得到最终的匹配结果。本文还提出几种措施来降低计算复杂度&#x…...

华为OD机试题 - 开放日活动(JavaScript)

最近更新的博客 2023新华为OD机试题 - 斗地主(JavaScript)2023新华为OD机试题 - 箱子之形摆放(JavaScript)2023新华为OD机试题 - 考古学家(JavaScript)2023新华为OD机试题 - 相同数字的积木游戏 1(JavaScript)2023新华为OD机试题 - 最多等和不相交连续子序列(JavaScri…...

(考研湖科大教书匠计算机网络)第四章网络层-第八节:网际控制报文协议ICMP

获取pdf&#xff1a;密码7281专栏目录首页&#xff1a;【专栏必读】考研湖科大教书匠计算机网络笔记导航 文章目录一&#xff1a;网际控制报文协议ICMP&#xff08;1&#xff09;ICMP差错报告报文A&#xff1a;终点不可达B&#xff1a;源点抑制C&#xff1a;时间超过D&#xff…...

华为OD机试 - GPU 调度 | 备考思路,刷题要点,答疑 【新解法】

最近更新的博客 【新解法】华为OD机试 - 关联子串 | 备考思路,刷题要点,答疑,od Base 提供【新解法】华为OD机试 - 停车场最大距离 | 备考思路,刷题要点,答疑,od Base 提供【新解法】华为OD机试 - 任务调度 | 备考思路,刷题要点,答疑,od Base 提供【新解法】华为OD机试…...

华为OD机试题 - 任务总执行时长(JavaScript)

最近更新的博客 2023新华为OD机试题 - 斗地主(JavaScript)2023新华为OD机试题 - 箱子之形摆放(JavaScript)2023新华为OD机试题 - 考古学家(JavaScript)2023新华为OD机试题 - 相同数字的积木游戏 1(JavaScript)2023新华为OD机试题 - 最多等和不相交连续子序列(JavaScri…...

还在想假期去哪玩?直接做一个旅游攻略小程序

憋了几年好不容易解封准备出去散散心,但看着大江南北这么多景点是不是有点让你选择强迫症呢?那就先制作一个旅游攻略小程序看看驴友们的分享吧。...

十四、vue3项目如何使用three.js

近期在开发过程中&#xff0c;因为项目已经接近尾声&#xff0c;就需要对项目中的数据进行整合&#xff0c;而数据看板不失为一个比较直观的展现形式。在数据看板中3D的展现形式是比较流行的展现形式&#xff0c;那么如何在项目引入一个大的场景&#xff0c;并且能够和后台发生…...

python 向excel表中添加新的sheet页或者向旧sheet中写入数据

import xlwt import xlrd from xlutils.copy import copy import os import numpy as np import pandas as pd class Excel_Add_Sheet():def save_table(self, table, file_name):# 保存表table.save(file_name)def add_new_sheet(self, file_name, sheet_name, titleNone):&q…...

RPC-grpc实践

参考&#xff1a;https://developer.aliyun.com/article/1152352?spma2c6h.12873639.article-detail.33.344f6446zEnbRi&scm20140722.ID_communityarticle1152352._.ID_communityarticle1152352-OR_rec-V_1 参考&#xff1a;https://onejson.blog.csdn.net/article/detai…...

JavaEE——MyBatis配置文件的详细介绍

简单介绍&#xff1a; 需要我们编写的配置文件主要有三个&#xff0c;分别是核心配置文件&#xff08;mybatis-config.xml&#xff09;&#xff0c;数据库连接信息文件&#xff08;db.properties&#xff09;&#xff0c;SQL语句映射文件&#xff08;Mappers&#xff09;&…...

bwmarrin/snowflake生成ID重复问题排查记录

现象 某日&#xff0c;运营反馈&#xff0c;在某个时间区间丢失了一段日志&#xff0c;让看看是什么问题。 排查 查看项目日志有无错误 发现项目日志有报错信息Error 1062 Duplicate entry 149059529550598144 for key PRIMARY,很显然&#xff0c;问题在此&#xff0c;数据库…...

操作系统题目收录(十)

1、在存储管理中&#xff0c;采用覆盖与交换技术的目的是&#xff08;&#xff09;。 A&#xff1a;节省主存空间B&#xff1a;物理上扩充主存容量C&#xff1a;提高CPU效率D&#xff1a;实现主存共享 解析 覆盖和交换的提出就是为了解决主存空间不足的问题&#xff0c;但不…...

IOS 自动化测试环境搭建

购买MacPDD 比TB JD 便宜500&#xff0c;下单安装homebrew/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"安装npm cnpmbrew install node; npm install -g cnpm --registryhttps://registry.npm.taobao.org;安装类似Andro…...

系统设计原则

系统设计原则 好的系统是迭代出来的。先解决核心问题&#xff0c;预测未来可能出现的问题&#xff0c;对现有的问题有方案&#xff0c;对未来的问题有预案。不是一上来就按1亿用户量设计&#xff0c;也不要过度复杂化系统。 业务千变万化&#xff0c;技术层出不穷&#xff0c…...

推荐130个网站,非常实用,比涨工资都重要

搞学习 TED&#xff08;最优质的演讲&#xff09;&#xff1a;https://www.ted.com/ 谷粉学术&#xff1a;https://gfsoso.99lb.net/scholar.html 大学资源网&#xff1a;http://www.dxzy163.com/ 简答题&#xff1a;http://www.jiandati.com/ 网易公开课&#xff1a;https…...

手机棋牌游戏开发的流程是怎样的?

最近几年&#xff0c;随着网络游戏的兴起&#xff0c;棋牌手游开发也越来越受欢迎&#xff0c;在国内&#xff0c;几乎随处可见从事手游和手游的公司。不过&#xff0c;虽然公司和产品很多&#xff0c;但效果也不一样&#xff0c;区别就在于&#xff0c;他们能不能掌握好这款游…...

浅谈C++函数重载

C相较于C语言来说,重载是一重大特性,让我们一起简单的回顾一下重载那些事 传送门函数重载是什么为什么有函数重载函数重载是如何实现的总结函数重载是什么 函数重载:是函数的一种特殊情况,C允许在同一作用域中声明几个功能相似的同名函数 这些同名函数的形参列表(参数个数or类…...

ubuntu搭建nfs服务centos挂载访问

在Ubuntu上设置NFS服务器 在Ubuntu上&#xff0c;你可以使用apt包管理器来安装NFS服务器。打开终端并运行&#xff1a; sudo apt update sudo apt install nfs-kernel-server创建共享目录 创建一个目录用于共享&#xff0c;例如/shared&#xff1a; sudo mkdir /shared sud…...

高频面试之3Zookeeper

高频面试之3Zookeeper 文章目录 高频面试之3Zookeeper3.1 常用命令3.2 选举机制3.3 Zookeeper符合法则中哪两个&#xff1f;3.4 Zookeeper脑裂3.5 Zookeeper用来干嘛了 3.1 常用命令 ls、get、create、delete、deleteall3.2 选举机制 半数机制&#xff08;过半机制&#xff0…...

鸿蒙中用HarmonyOS SDK应用服务 HarmonyOS5开发一个医院挂号小程序

一、开发准备 ​​环境搭建​​&#xff1a; 安装DevEco Studio 3.0或更高版本配置HarmonyOS SDK申请开发者账号 ​​项目创建​​&#xff1a; File > New > Create Project > Application (选择"Empty Ability") 二、核心功能实现 1. 医院科室展示 /…...

P3 QT项目----记事本(3.8)

3.8 记事本项目总结 项目源码 1.main.cpp #include "widget.h" #include <QApplication> int main(int argc, char *argv[]) {QApplication a(argc, argv);Widget w;w.show();return a.exec(); } 2.widget.cpp #include "widget.h" #include &q…...

数据链路层的主要功能是什么

数据链路层&#xff08;OSI模型第2层&#xff09;的核心功能是在相邻网络节点&#xff08;如交换机、主机&#xff09;间提供可靠的数据帧传输服务&#xff0c;主要职责包括&#xff1a; &#x1f511; 核心功能详解&#xff1a; 帧封装与解封装 封装&#xff1a; 将网络层下发…...

【决胜公务员考试】求职OMG——见面课测验1

2025最新版&#xff01;&#xff01;&#xff01;6.8截至答题&#xff0c;大家注意呀&#xff01; 博主码字不易点个关注吧,祝期末顺利~~ 1.单选题(2分) 下列说法错误的是:&#xff08; B &#xff09; A.选调生属于公务员系统 B.公务员属于事业编 C.选调生有基层锻炼的要求 D…...

04-初识css

一、css样式引入 1.1.内部样式 <div style"width: 100px;"></div>1.2.外部样式 1.2.1.外部样式1 <style>.aa {width: 100px;} </style> <div class"aa"></div>1.2.2.外部样式2 <!-- rel内表面引入的是style样…...

工业自动化时代的精准装配革新:迁移科技3D视觉系统如何重塑机器人定位装配

AI3D视觉的工业赋能者 迁移科技成立于2017年&#xff0c;作为行业领先的3D工业相机及视觉系统供应商&#xff0c;累计完成数亿元融资。其核心技术覆盖硬件设计、算法优化及软件集成&#xff0c;通过稳定、易用、高回报的AI3D视觉系统&#xff0c;为汽车、新能源、金属制造等行…...

k8s业务程序联调工具-KtConnect

概述 原理 工具作用是建立了一个从本地到集群的单向VPN&#xff0c;根据VPN原理&#xff0c;打通两个内网必然需要借助一个公共中继节点&#xff0c;ktconnect工具巧妙的利用k8s原生的portforward能力&#xff0c;简化了建立连接的过程&#xff0c;apiserver间接起到了中继节…...

华为云Flexus+DeepSeek征文|DeepSeek-V3/R1 商用服务开通全流程与本地部署搭建

华为云FlexusDeepSeek征文&#xff5c;DeepSeek-V3/R1 商用服务开通全流程与本地部署搭建 前言 如今大模型其性能出色&#xff0c;华为云 ModelArts Studio_MaaS大模型即服务平台华为云内置了大模型&#xff0c;能助力我们轻松驾驭 DeepSeek-V3/R1&#xff0c;本文中将分享如何…...