Qt 5.13 编译 qtopcua 源码

编译环境

  • Windows 10
  • Qt 5.13.2
  • MinGW 7.3.0

编译

(1)编译前,请先确保本机已安装了 Perl。

下载地址:Strawberry Perl for Windows

(2)点击屏幕左下角的 Windows 图标,在打开的开始菜单栏中,找到 Qt 5.13.2 目录,启动命令行。

(3)下载 qtopcua 源码。

git clone https://github.com/qt/qtopcua.git -b 5.13.2

(4)先导航到 qtopcua 目录,创建一个 build 目录,用于存放待会编译完的代码,再导航到到 build 目录。

cd qtopcua && mkdir build && cd build

(5)构建。

qmake ..

(6)编译。

mingw32-make

编译这一步可能会比较花时间,请耐心等待。

(7)安装。

mingw32-make install

测试

(1)打开 Qt Creator,随便创建一个项目,在生成的 .pro 文件中,添加以下代码:

QT += opcua

(2)在 mainwindow.cpp 文件中,编写创建客户端的代码。

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QOpcUaProvider>
#include <QOpcUaClient>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    QOpcUaProvider provider;
    QOpcUaClient *opcuaClient = nullptr;

    opcuaClient = provider.createClient("open62541");


    if(opcuaClient)
    {
        qDebug() << "客户端创建成功!";
    }

}

MainWindow::~MainWindow()
{
    delete ui;
}

(3)Qt 5 版本的 qtopcua 库参考文档:Qt OPC UA Overview | Qt OPC UA 5.15.13

参考资料

[1] Building Qt OPC UA with open62541 - basysKom

posted @ 2023-03-26 14:41  一鹿顺风117  阅读(851)  评论(0编辑  收藏  举报