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

测词汇量的专业网站网站建设导入视频

测词汇量的专业网站,网站建设导入视频,企业注册信息,自己如何建立网站文章目录 项目#xff1a;网路项目1#xff1a;主机信息查询1.1 QHostInfo类和QNetworkInterface类1.2 主机信息查询项目实现 项目2#xff1a;基于HTTP的网络应用程序2.1 项目中用到的函数详解2.2 主要源码 项目#xff1a;网路 项目1#xff1a;主机信息查询 使用QHostI… 文章目录 项目网路项目1主机信息查询1.1 QHostInfo类和QNetworkInterface类1.2 主机信息查询项目实现 项目2基于HTTP的网络应用程序2.1 项目中用到的函数详解2.2 主要源码 项目网路 项目1主机信息查询 使用QHostInfo类和QNetworkInterface类可以获取主机的一些网络信息如IP地址1和MAC地址2。 在Qt项目里使用Qt Network模块需要在项目配置文件(.pro 文件)中增加一条配置语句 QT network 1.1 QHostInfo类和QNetworkInterface类 QHostInfo类常用函数 QHostInfo类可以根据主机名获取主机的IP地址或者通过IP地址获取主机名。 [static] QString QHostInfo::localHostName()返回本机主机名[static] QString QHostInfo::localDomainName()返回本机域名系统(domain name systemDNS)域名[static] QHostInfo QHostInfo::fromName(const QString name)返回指定主机名的IP地址[static] int QHostInfo::lookupHost(const QString name, QObject *receiver, const char *member)以异步的方式根据主机名查找主机的IP地址并返回一个表示本次查找的ID可用作abortHostLookup()函数的参数[static] void QHostInfo::abortHostLookup(int id)使用 lookupHost() 返回的 ID 终止主机查找。QListQHostAddress QHostInfo::addresses() const返回与hostName()对应主机关联的IP地址列表QString QHostInfo::hostName() const返回通过IP地址查找到的主机名 QNetworkInterface类常用的函数 QNetworkInterface类可以获得运行程序的主机名的所用IP地址和网络接口列表。 [static] QList QNetworkInterface::allAddresses()返回主机上所有IP地址的列表(如果不需要知道子网掩码和广播地址)[static] QList QNetworkInterface::allInterfaces()返回主机上所有网络接口列表(一个网络接口可能包含多个IP地址每个IP地址与掩码或广播地址关联)QList QNetworkInterface::addressEntries() const返回网络接口的IP地址列表包括子网掩码和广播地址QString QNetworkInterface::hardwareAddress() const返回接口的低级硬件地址以太网里就是MAC地址bool QNetworkInterface::isValid() const如果接口信息有效就返回trueQNetworkInterface::InterfaceType QNetworkInterface::type() const返回网络接口的类型 1.2 主机信息查询项目实现 显示本机地址信息 //获取本机主机名和IP地址按钮 void Widget::on_btnGetHostInfo_clicked() {ui-plainTextEdit-clear();QString hostName QHostInfo::localHostName(); //本机主机名qDebug()hostName;ui-plainTextEdit-appendPlainText(HostName:hostName\n);QHostInfo hostInfo QHostInfo::fromName(hostName); //本机IP地址QListQHostAddress addrList hostInfo.addresses();//IP地址列表if(addrList.isEmpty()) return;foreach(QHostAddress host, addrList){bool show ui-checkBox_OnlyIPV4-isChecked(); //只显示ipv4//Returns the network layer protocol of the host address.show show ? (host.protocol() QAbstractSocket::IPv4Protocol):true;if(show){ui-plainTextEdit-appendPlainText(protool:protocolName(host.protocol()));//协议ui-plainTextEdit-appendPlainText(HostIPAdddress:host.toString());ui-plainTextEdit-appendPlainText(QString(isGolbal() %1\n).arg(host.isGlobal()));}} }protocol()函数返回主机地址的网络层协议。 QAbstractSocket::NetworkLayerProtocol QHostAddress::protocol() const Returns the network layer protocol of the host address.isGlobal()函数如果地址是 IPv4 或 IPv6 全局地址则返回 true否则返回 false。全局地址是不为特殊目的如环回或多播或未来目的保留的地址。 bool QHostAddress::isGlobal() const Returns true if the address is an IPv4 or IPv6 global address, false otherwise. A global address is an address that is not reserved for special purposes (like loopback or multicast) or future purposes.自定义函数protocolName()通过协议类型返回协议名称字符串。 //通过协议类型返回协议名称字符串 QString Widget::protocolName(QAbstractSocket::NetworkLayerProtocol protocol) {switch (protocol) {case QAbstractSocket::IPv4Protocol:return IPV4;case QAbstractSocket::IPv6Protocol:return IPV6;case QAbstractSocket::AnyIPProtocol:return Any Internet Protocol;default:return Unknown NetWork Layer Protocol;} }查找主机地址信息 [static] int QHostInfo::lookupHost(const QString name, QObject *receiver, const char *member): name表示主机名的字符串可以是主机名、域名或IP地址receive和member指定接收者和槽函数名称。 //查找域名的IP地址 void Widget::on_btnLookkup_clicked() {ui-plainTextEdit-clear();QString hostName ui-comboBox-currentText(); //读取主机名ui-plainTextEdit-appendPlainText(Searching for host information:hostName\n);QHostInfo::lookupHost(hostName, this,SLOT(do_lookedUpHostInfo(QHostInfo))); }//查找主机信息的槽函数 void Widget::do_lookedUpHostInfo(const QHostInfo host) {QListQHostAddress addrList host.addresses(); //获取主机地址列表if(addrList.isEmpty())return;foreach(QHostAddress host, addrList){bool show ui-checkBox_OnlyIPV4-isChecked(); //只显示ipv4//Returns the network layer protocol of the host address.show show ? (host.protocol() QAbstractSocket::IPv4Protocol):true;if(show){ui-plainTextEdit-appendPlainText(protool:protocolName(host.protocol()));//协议ui-plainTextEdit-appendPlainText(host.toString());ui-plainTextEdit-appendPlainText(QString(isGolbal() %1\n).arg(host.isGlobal()));}} }QNetworkInterface类的使用 //根据枚举值返回字符串 QString Widget::interfaceType(QNetworkInterface::InterfaceType type) {switch(type){case QNetworkInterface::Unknown:return Unkown;case QNetworkInterface::Loopback:return Loopback;case QNetworkInterface::Ethernet:return Etherent;case QNetworkInterface::Wifi:return Wifi;default:return Other type;} }//allInterfaces() void Widget::on_btnAllInterface_2_clicked() {ui-plainTextEdit-clear();QListQNetworkInterface list QNetworkInterface::allInterfaces();//网络接口列表foreach(QNetworkInterface interface,list){if(!interface.isValid())continue; // The name of the device // Hardware devices // Interface type // Subnet mask // broadcast addressui-plainTextEdit-appendPlainText(The name of the device:interface.humanReadableName());ui-plainTextEdit-appendPlainText(Hardware devices:interface.hardwareAddress());ui-plainTextEdit-appendPlainText(Interface type:interfaceType(interface.type()));QListQNetworkAddressEntry entryList interface.addressEntries();//地址列表foreach(QNetworkAddressEntry entry, entryList){ui-plainTextEdit-appendPlainText( IP Address:entry.ip().toString());ui-plainTextEdit-appendPlainText( Subnet mask:entry.netmask().toString());ui-plainTextEdit-appendPlainText( broadcast address:entry.broadcast().toString()\n);}} }//alladdress void Widget::on_btnAllAddress_clicked() {ui-plainTextEdit-clear();QListQHostAddress addrelist QNetworkInterface::allAddresses();//IP地址列表if(addrelist.isEmpty()) return;foreach(QHostAddress host, addrelist){bool show ui-checkBox_OnlyIPV4-isChecked();show show ? (host.protocol() QAbstractSocket::IPv4Protocol):true;if(show){ui-plainTextEdit-appendPlainText(protocol:protocolName(host.protocol()));ui-plainTextEdit-appendPlainText(IP Address:host.toString());ui-plainTextEdit-appendPlainText(QString(isGrobal() %1\n).arg(host.isGlobal()));}} } Loopback: 回送地址Loopback Address是本机回送地址127.X.X.X即主机IP堆栈内部的IP地址主要用于网络软件测试以及本地机进程间通信。因此无论什么程序一旦使用回送地址发送数据协议软件会立即将其返回不进行任何网络传输。127.0.0.1是回送地址又指本地机一般用来测试使用。 项目2基于HTTP的网络应用程序 QNetworkRequest 类通过 URL 发起网络协议请求其也保存网络请求的信息目前支持 HTTP、 FTP 和本地文件 URL 的下载或上传。 QNetworkAccessManager 类用于协调网络操作在 QNetworkRequest 发起网络请求后 QNetworkAccessManager 负责发送网络请求以及创建网络响应。 QNetworkReply 类表示网络请求的响应由 QNetworkAccessManager 在发送网络请求后创建网 络响应。QNetworkReply 提供的信号 finished()、readyRead()、downloadProgress()可用于监测网络响 应的执行情况从而进行相应的操作。 #mermaid-svg-MRbivWyLLOAkyBLv {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg-MRbivWyLLOAkyBLv .error-icon{fill:#552222;}#mermaid-svg-MRbivWyLLOAkyBLv .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-MRbivWyLLOAkyBLv .edge-thickness-normal{stroke-width:2px;}#mermaid-svg-MRbivWyLLOAkyBLv .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-MRbivWyLLOAkyBLv .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-MRbivWyLLOAkyBLv .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-MRbivWyLLOAkyBLv .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-MRbivWyLLOAkyBLv .marker{fill:#333333;stroke:#333333;}#mermaid-svg-MRbivWyLLOAkyBLv .marker.cross{stroke:#333333;}#mermaid-svg-MRbivWyLLOAkyBLv svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-MRbivWyLLOAkyBLv .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-MRbivWyLLOAkyBLv .cluster-label text{fill:#333;}#mermaid-svg-MRbivWyLLOAkyBLv .cluster-label span{color:#333;}#mermaid-svg-MRbivWyLLOAkyBLv .label text,#mermaid-svg-MRbivWyLLOAkyBLv span{fill:#333;color:#333;}#mermaid-svg-MRbivWyLLOAkyBLv .node rect,#mermaid-svg-MRbivWyLLOAkyBLv .node circle,#mermaid-svg-MRbivWyLLOAkyBLv .node ellipse,#mermaid-svg-MRbivWyLLOAkyBLv .node polygon,#mermaid-svg-MRbivWyLLOAkyBLv .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-MRbivWyLLOAkyBLv .node .label{text-align:center;}#mermaid-svg-MRbivWyLLOAkyBLv .node.clickable{cursor:pointer;}#mermaid-svg-MRbivWyLLOAkyBLv .arrowheadPath{fill:#333333;}#mermaid-svg-MRbivWyLLOAkyBLv .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-MRbivWyLLOAkyBLv .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-MRbivWyLLOAkyBLv .edgeLabel{background-color:#e8e8e8;text-align:center;}#mermaid-svg-MRbivWyLLOAkyBLv .edgeLabel rect{opacity:0.5;background-color:#e8e8e8;fill:#e8e8e8;}#mermaid-svg-MRbivWyLLOAkyBLv .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-MRbivWyLLOAkyBLv .cluster text{fill:#333;}#mermaid-svg-MRbivWyLLOAkyBLv .cluster span{color:#333;}#mermaid-svg-MRbivWyLLOAkyBLv div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-MRbivWyLLOAkyBLv :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} 发起网络协议请求 发送网络请求以及创建网络响应 监测网络响应 2.1 项目中用到的函数详解 clearButtonEnabled : bool 此属性用于保存行编辑在不为空时是否显示清除按钮。 如果启用行编辑在包含一些文本时会显示一个尾随清除按钮否则行编辑不会显示清除按钮默认值。 默认路径按钮功能 [static] QString QDir::currentPath() 返回应用进程当前目录的绝对路径。当前目录是使用 QDirsetCurrent 设置的最后一个目录或者如果从未调用过则为父进程启动此应用进程的目录。bool QDir::mkdir(const QString dirName) const 创建一个名为 dirName 的子目录。 下载按钮功能 QString QString::trimmed() const 返回一个字符串该字符串删除了开头和结尾的空格。[static] QUrl QUrl::fromUserInput(const QString userInput) 从用户提供的 userInput 字符串返回有效的 URL如果可以扣除。如果不可能则返回无效的 QUrl。QString QUrl::errorString() const 如果修改此 QUrl 对象的最后一个操作遇到解析错误则返回错误消息。如果未检测到错误则此函数返回一个空字符串isValid 返回 true。QString QUrl::fileName(QUrl::ComponentFormattingOptions options FullyDecoded) const 返回文档名,不包括目录路径。bool QFile::remove() 删除 fileName 指定的文档。如果成功则返回 true;否则返回 false。文档在删除之前已关闭。QNetworkReply *QNetworkAccessManager::get(const QNetworkRequest request) 发布一个请求以获取目标请求的内容并返回一个新的 QNetworkReply 对象该对象打开以供读取每当新数据到达时该对象都会发出 readyRead 信号。将下载内容以及相关的标题。[signal] void QIODevice::readyRead() 每当有新数据可用时此信号就会发出一次从设备的当前读取信道读取。只有当有新数据可用时它才会再次发出例如当新的网络数据有效负载到达您的网络套接字时或者当新的数据块附加到您的设备时。[signal] void QNetworkReply::downloadProgress(qint64 bytesReceived, qint64 bytesTotal) 发出此信号以指示此网络请求的下载部分的进度如果有。如果没有与此请求关联的下载则此信号将发出一次其中 0 作为 bytesReceived 和 bytesTotal 的值。[signal] void QNetworkReply::finished() 当回复完成处理时将发出此信号。发出此信号后回复的数据或元数据将不再更新。 读取下载数据 qint64 QIODevice::write(const char *data, qint64 maxSize) 将数据中最多 maxSize 字节的数据写入设备。返回实际写入的字节数如果发生错误则返回 -1。 QByteArray QIODevice::readAll() 从设备读取所有剩余数据并将其作为字节数组返回。 2.2 主要源码 头文件 #ifndef WIDGET_H #define WIDGET_H#include QWidget #include QNetworkAccessManager #include QFile #include QMessageBox #include QIODevice #include QNetworkReply #include QDesktopServices #include QFileInfo #include QUrlnamespace Ui { class Widget; }class Widget : public QWidget {Q_OBJECT private:QNetworkAccessManager networkManager; //网络管理QNetworkReply *reply; //网络响应QFile *downloadedFile; //下载保存的临时文件 public:explicit Widget(QWidget *parent nullptr);~Widget(); private slots:void do_finished();void do_readyRead();void do_downloadProgress(qint64 bytesRead, qint64 totalBytes);void on_btnDownload_clicked();void on_btnDefaultPath_clicked();void on_editURL_textChanged(const QString arg1);private:Ui::Widget *ui; };#endif // WIDGET_H 源文件 #include widget.h #include ui_widget.h#include QDirWidget::Widget(QWidget *parent) :QWidget(parent),ui(new Ui::Widget) {ui-setupUi(this); //clearButtonEnabled : bool //This property holds whether the line edit displays a clear button when it is not empty. //If enabled, the line edit displays a trailing clear button when it contains some text, // otherwise the line edit does not show a clear button (the default).ui-editURL-setClearButtonEnabled(true);this-setLayout(ui-verticalLayout); }Widget::~Widget() {delete ui; }void Widget::do_finished() {//网络响应结束QFileInfo fileInfo(downloadedFile-fileName()); //获取下载文件的文件名downloadedFile-close();delete downloadedFile; //删除临时文件reply-deleteLater(); //由主事件循环删除此文件对象if(ui-checkBoxOpen-isChecked()){QDesktopServices::openUrl(QUrl::fromLocalFile(fileInfo.absoluteFilePath()));}ui-btnDownload-setEnabled(true); }void Widget::do_readyRead() {//读取下载数据downloadedFile-write(reply-readAll()); // qint64 QIODevice::write(const char *data, qint64 maxSize) // Writes at most maxSize bytes of data from data to the device. // Returns the number of bytes that were actually written, // or -1 if an error occurred. // QByteArray QIODevice::readAll() // Reads all remaining data from the device, and returns it as a byte array.}void Widget::do_downloadProgress(qint64 bytesRead, qint64 totalBytes) {//下载进度ui-progressBar-setMaximum(totalBytes);//Holds the total amount of data to download in bytes.ui-progressBar-setValue(bytesRead); }//默认了路径 按钮 void Widget::on_btnDefaultPath_clicked() { // [static] QString QDir::currentPath() // Returns the absolute path of the applications current directory. // The current directory is the last directory set with QDir::setCurrent() or, // if that was never called, // the directory at which this application was started at by the parent process.QString curPath QDir::currentPath(); //返回当前绝对路径给QString变量QDir dir(curPath); //定义QDir变量QString sub temp; // bool QDir::mkdir(const QString dirName) const // Creates a sub-directory called dirName.dir.mkdir(sub); //当前路径下创立名为sub的文件夹ui-editPath-setText(curPath/sub/); //设置lineedit的文字 }//下载按钮开始下载 void Widget::on_btnDownload_clicked() { // QString QString::trimmed() const // Returns a string that has whitespace removed from the start and the end.QString urlSpec ui-editURL-text().trimmed(); //将editURL中的文字给QString变量赋值//urlspec判空if(urlSpec.isEmpty()){QMessageBox::information(this,error,Please specify the download address);return;} // [static] QUrl QUrl::fromUserInput(const QString userInput) // Returns a valid URL from a user supplied userInput string if one can be deducted. // In the case that is not possible, an invalid QUrl() is returned.QUrl newUrl QUrl::fromUserInput(urlSpec); //从urlSpaec里获取url//newurl判有效if(!newUrl.isValid()){ // QString QUrl::errorString() const // Returns an error message if the last operation that modified this QUrl object ran into a parsing error. // If no error was detected, // this function returns an empty string and isValid() returns true.QString info The URL is invalid:urlSpec\n error:newUrl.errorString();QMessageBox::information(this,error,info);return;}QString tempDir ui-editPath-text().trimmed(); //临时目录if(tempDir.isEmpty()){QMessageBox::information(this,error,Please specify the download address);return;}QString fullFileName tempDir newUrl.fileName(); //文件名 // QString QUrl::fileName(QUrl::ComponentFormattingOptions options FullyDecoded) const // Returns the name of the file, excluding the directory path.if(QFile::exists(fullFileName)){ //如果文件存在QFile::remove(fullFileName); //删除文件 // bool QFile::remove() // Removes the file specified by fileName(). Returns true if successful; otherwise returns false. // The file is closed before it is removed.}downloadedFile new QFile(fullFileName); //创建临时文件if(!downloadedFile-open(QIODevice::WriteOnly)){QMessageBox::information(this,error,Temporary file open error);}ui-btnDownload-setEnabled(false);//发送网络请求创建网络相应reply networkManager.get(QNetworkRequest(newUrl)); //网络响应从网络管理里面获取网络请求 // QNetworkReply *QNetworkAccessManager::get(const QNetworkRequest request) // Posts a request to obtain the contents of the target request and // returns a new QNetworkReply object opened for reading // which emits the readyRead() signal whenever new data arrives. // The contents as well as associated headers will be downloaded. // QObject *QObject::parent() const // Returns a pointer to the parent object.connect(reply, SIGNAL(readyRead()), this, SLOT(do_readyRead()));connect(reply, SIGNAL(downloadProgress(qint64,qint64)),this, SLOT(do_downloadProgress(qint64,qint64)));connect(reply, SIGNAL(finished()), this, SLOT(do_finished())); // [signal] void QIODevice::readyRead() // This signal is emitted once every time new data is available for // reading from the devices current read channel. // It will only be emitted again once new data is available, // such as when a new payload of network data has arrived on your network socket, // or when a new block of data has been appended to your device. // [signal] void QNetworkReply::downloadProgress(qint64 bytesReceived, qint64 bytesTotal) // This signal is emitted to indicate the progress of the download part of // this network request, if theres any. If theres no download associated with this request, // this signal will be emitted once with 0 as the value of both bytesReceived and bytesTotal. // [signal] void QNetworkReply::finished() // This signal is emitted when the reply has finished processing. // After this signal is emitted, there will be no more updates to the replys data or metadata. }void Widget::on_editURL_textChanged(const QString arg1) {Q_UNUSED(arg1);ui-progressBar-setMaximum(100);ui-progressBar-setValue(0); } IP地址Internet Protocol Address是指互联网协议地址又译为网际协议地址。IP地址是IP协议提供的一种统一的地址格式它为互联网上的每一个网络和每一台主机分配一个逻辑地址以此来屏蔽物理地址的差异。 ↩︎ MAC地址英语Media Access Control Address直译为媒体存取控制位址也称为局域网地址LAN AddressMAC位址以太网地址Ethernet Address或物理地址Physical Address它是一个用来确认网络设备位置的位址。在OSI模型中第三层网络层负责IP地址第二层数据链路层则负责MAC位址。MAC地址用于在网络中唯一标示一个网卡一台设备若有一或多个网卡则每个网卡都需要并会有一个唯一的MAC地址。 ↩︎
http://www.hkea.cn/news/14415808/

相关文章:

  • 手机免费建立网站济南seo优化公司
  • 做淘宝推广开网站合适全屋定制品牌推荐
  • 建材公司网站建设方案我爱777在线观看
  • p2p网站建设后期维护私人pk赛车网站怎么做
  • 如何做网站豆瓣厦门seo网络推广
  • 免费建站系统下载乐平网站
  • dw做的网站能搜到吗wordpress主题柚子皮zip
  • 兔展在线制作网站html网页制作总结
  • 榆林尚呈高端网站建设学院评估 网站建设整改
  • 品牌企业网站建设公司价格网站开发端口查询
  • 网站建设有哪些问题视频网站建站程序
  • 做照片视频的网站资讯型电商网站优缺点
  • 襄阳手机网站建设合肥房产网365
  • 织梦网站栏目江苏省建设执业资格中心网站
  • 网站开发 视频播放器wordpress 好用插件
  • 学校网站设计思路系统集成项目管理
  • windows 2003做网站如何知道wordpress
  • html网站免费模板开发公司移交给物业资料说明
  • 做英文网站怎么赚钱网站做流量的论坛贴吧
  • 建站公司网站 phpwind网站建议反馈应该怎么做
  • 廊坊哪里能够做网站微信公众号做电影网站要域名吗
  • 网站建设目的与作用织梦系统做的网站打开慢
  • 龙岗网站建设工程17网站一起做网店质量怎么样
  • 营销型网站的建设重点是什么做爰视频网站在线看
  • 福永网站优化网站开发策划
  • 电子商务网站建设 教案北京如何优化网站
  • 天津建设网站公司高港区拖拽式网页制作平台
  • 四川微信网站建设蓝海电商怎么做
  • 购物帮做特惠的导购网站成都公司注册流程及费用
  • 工程网站建设最新国际新闻热点