{"id":660,"date":"2018-01-16T12:38:00","date_gmt":"2018-01-16T11:38:00","guid":{"rendered":"https:\/\/blog2.basyskom.com\/?p=660"},"modified":"2024-01-04T17:24:59","modified_gmt":"2024-01-04T16:24:59","slug":"want-to-give-qt-opcua-a-try","status":"publish","type":"post","link":"https:\/\/www.basyskom.de\/en\/want-to-give-qt-opcua-a-try\/","title":{"rendered":"Want to give Qt OpcUa a try?"},"content":{"rendered":"\t\t<div data-elementor-type=\"wp-post\" data-elementor-id=\"660\" class=\"elementor elementor-660\" data-elementor-post-type=\"post\">\n\t\t\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-759d65f3 elementor-section-boxed elementor-section-height-default elementor-section-height-default wpr-particle-no wpr-jarallax-no wpr-parallax-no wpr-sticky-section-no wpr-equal-height-no\" data-id=\"759d65f3\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-b26633b\" data-id=\"b26633b\" data-element_type=\"column\" data-e-type=\"column\" data-settings=\"{&quot;animation&quot;:&quot;none&quot;}\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<section class=\"elementor-section elementor-inner-section elementor-element elementor-element-b9288ea elementor-section-boxed elementor-section-height-default elementor-section-height-default wpr-particle-no wpr-jarallax-no wpr-parallax-no wpr-sticky-section-no wpr-equal-height-no\" data-id=\"b9288ea\" data-element_type=\"section\" data-e-type=\"section\" data-settings=\"{&quot;background_background&quot;:&quot;classic&quot;,&quot;animation&quot;:&quot;none&quot;}\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-50 elementor-inner-column elementor-element elementor-element-99fcfc1\" data-id=\"99fcfc1\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-5cd2414 elementor-view-default elementor-widget elementor-widget-icon\" data-id=\"5cd2414\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"icon.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-icon-wrapper\">\n\t\t\t<div class=\"elementor-icon\">\n\t\t\t<svg aria-hidden=\"true\" class=\"e-font-icon-svg e-fas-exclamation-circle\" viewBox=\"0 0 512 512\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\"><path d=\"M504 256c0 136.997-111.043 248-248 248S8 392.997 8 256C8 119.083 119.043 8 256 8s248 111.083 248 248zm-248 50c-25.405 0-46 20.595-46 46s20.595 46 46 46 46-20.595 46-46-20.595-46-46-46zm-43.673-165.346l7.418 136c.347 6.364 5.609 11.346 11.982 11.346h48.546c6.373 0 11.635-4.982 11.982-11.346l7.418-136c.375-6.874-5.098-12.654-11.982-12.654h-63.383c-6.884 0-12.356 5.78-11.981 12.654z\"><\/path><\/svg>\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t<div class=\"elementor-column elementor-col-50 elementor-inner-column elementor-element elementor-element-a68665b\" data-id=\"a68665b\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-c2628d3 elementor-widget elementor-widget-text-editor\" data-id=\"c2628d3\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p style=\"text-align: center;\"><span style=\"color: #ffffff;\"><strong>Update 02.03.2018:<\/strong> the steps outlined below have become outdated.<br \/><\/span><span style=\"color: #ffffff;\">Please see <span style=\"color: #000000;\"><a style=\"color: #000000;\" href=\"https:\/\/www.basyskom.de\/building-qt-opc-ua-with-open62541\/\">here<\/a><\/span> for up to date build steps.<\/span><\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<div class=\"elementor-element elementor-element-b10a7ec elementor-widget-divider--separator-type-pattern elementor-widget-divider--no-spacing elementor-widget-divider--view-line elementor-widget elementor-widget-divider\" data-id=\"b10a7ec\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"divider.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-divider\" style=\"--divider-pattern-url: url(&quot;data:image\/svg+xml,%3Csvg xmlns=&#039;http:\/\/www.w3.org\/2000\/svg&#039; preserveAspectRatio=&#039;xMidYMid meet&#039; overflow=&#039;visible&#039; height=&#039;100%&#039; viewBox=&#039;0 0 126 26&#039; fill=&#039;black&#039; stroke=&#039;none&#039;%3E%3Cpath d=&#039;M10.7,6l2.5,2.6l-4,4.3l4,5.4l-2.5,1.9l-4.5-5.2l-3.9,4.2L0.7,17L4,13.1L0,8.6l2.3-1.3l3.9,3.9L10.7,6z M23.9,6.6l4.2,4.5L32,7.2l2.3,1.3l-4,4.5l3.2,3.9L32,19.1l-3.9-3.3l-4.5,4.3l-2.5-1.9l4.4-5.1l-4.2-3.9L23.9,6.6zM73.5,6L76,8.6l-4,4.3l4,5.4l-2.5,1.9l-4.5-5.2l-3.9,4.2L63.5,17l4.1-4.7L63.5,8l2.3-1.3l4.1,3.6L73.5,6z M94,6l2.5,2.6l-4,4.3l4,5.4L94,20.1l-3.9-5l-3.9,4.2L84,17l3.2-3.9L84,8.6l2.3-1.3l3.2,3.9L94,6z M106.9,6l4.5,5.1l3.9-3.9l2.3,1.3l-4,4.5l3.2,3.9l-1.6,2.1l-3.9-4.2l-4.5,5.2l-2.5-1.9l4-5.4l-4-4.3L106.9,6z M53.1,6l2.5,2.6l-4,4.3l4,4.6l-2.5,1.9l-4.5-4.5l-3.5,4.5L43.1,17l3.2-3.9l-4-4.5l2.3-1.3l3.9,3.9L53.1,6z&#039;\/%3E%3C\/svg%3E&quot;);\">\n\t\t\t<span class=\"elementor-divider-separator\">\n\t\t\t\t\t\t<\/span>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-2cf89f6 elementor-widget elementor-widget-text-editor\" data-id=\"2cf89f6\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>basysKom has initiated Qt OpcUa which is a module offering support for the industrial communication standard OPC UA. This module has been <a href=\"http:\/\/lists.qt-project.org\/pipermail\/development\/2015-September\/023150.html\" rel=\"nofollow noopener\" target=\"_blank\">contribut<\/a><a href=\"http:\/\/lists.qt-project.org\/pipermail\/development\/2015-September\/023150.html\" rel=\"nofollow noopener\" target=\"_blank\">ed<\/a>\u00a0by us to the Qt Project.\u00a0The\u00a0Qt OpcUa\u00a0API wraps existing OPC UA implementations. Currently, implementations for freeopcua and\u00a0<a href=\"https:\/\/open62541.org\/\" rel=\"nofollow noopener\" target=\"_blank\">open62541<\/a>\u00a0are available.<\/p><p>Qt OpcUa will become part of the Qt 5.11 release as a\u00a0Technology Preview. First\u00a0<a href=\"https:\/\/wiki.qt.io\/Qt_5.11_Release\" rel=\"nofollow noopener\" target=\"_blank\">alpha builds<\/a>\u00a0will be available by the end of February 2018.\u00a0Qt 5.11 release is scheduled for end of May 2018.<\/p><h3>Why not try out the current state of Qt OpcUa right now?<\/h3><p>We have been asked by a number of people how to get started already now. We will provide short howtos for Ubuntu, Windows-MinGW and Visual Studio 2017 in the following article.<\/p><p>Two things are needed: Qt OpcUa itself and an OPC UA library. In this article, we use open62541 as it has very little dependencies (and is the more complete implementation anyway).<\/p><p>The easiest approach to build Qt OpcUa is as a drop-in for Qt 5.10. This spares us from creating a full Qt build based on the current dev branch.<\/p><p>The following recipes assume that you have\u00a0cmake, python\/pip, perl, git and other essential build tools installed. Paths used with the examples need to be adjusted to reflect your local situation.<\/p><h3>Installation on Linux<\/h3><p>These steps have been tested on Ubuntu 16.04 but can be applied to a wide range of desktop distributions.<\/p><pre class=\"lang:sh decode:true\" title=\"Compiling open62541\">$ sudo pip install six\n$ git clone https:\/\/github.com\/open62541\/open62541.git\n$ cd open62541\n$ git checkout 302003d\n$ mkdir build &amp;&amp; cd build\n$ cmake -DBUILD_SHARED_LIBS=ON -DUA_ENABLE_AMALGAMATION=ON ..\n$ make\n$ sudo make install\n\n$ git clone http:\/\/code.qt.io\/qt\/qtopcua.git\n$ cd qtopcua\n$ mkdir build &amp;&amp; cd build\n$ \/opt\/Qt5.10\/5.10.0\/gcc_64\/bin\/qmake .. # has open62541 been detected?\n$ make \n$ sudo make install<\/pre><h3>Installation on Windows (Visual Studio 2017)<\/h3><p>Start by running the <em>Qt 5.10.0 64-bit for Desktop (MSVC 2017)<\/em> shell\u00a0shipped with Qt (have a look at the &#8220;Start Menu&#8221;). Use this shell to issue the following commands:<\/p><pre class=\"lang:default decode:true\">\"c:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\WDExpress\\VC\\Auxiliary\\Build\\vcvarsx86_amd64.bat\"\npip install six\ngit clone\u00a0https:\/\/github.com\/open62541\/open62541.git\ncd open62541\ngit checkout 302003d\nmkdir build\ncd build\ncmake.exe -G \"NMake Makefiles\" -DUA_ENABLE_AMALGAMATION=ON ..\nnmake.exe\n\ngit clone http:\/\/code.qt.io\/qt\/qtopcua.git\ncd qtopcua\nmkdir build\ncd build\nset INCLUDE=%INCLUDE%;c:\\path\\to\\open62541\\build\nset LIB=%LIB%;c:\\path\\to\\open62541\\build\\bin\nqmake.exe ..    # has open62541 been detected?\nnmake.exe\nnmame.exe install<\/pre><p>Above recipe will also work for Visual Studio 2015. 2013 is not supported (and will be dropped by Qt 5.11 anyways).<\/p><h3>Installation on Windows (MinGW as shipped with Qt 5.10)<\/h3><p>Start by running the <em>Qt 5.10.0 for Desktop (MinGW 5.3.0 32 bit)\u00a0<\/em>shell\u00a0shipped with Qt (have a look at the &#8220;Start Menu&#8221;). Use this shell to issue the following commands:<\/p><pre class=\"lang:default decode:true\">pip install six\ngit clone https:\/\/github.com\/open62541\/open62541.git\ncd open62541\ngit checkout 302003d\nmkdir build\ncd build\ncmake.exe -G \"MinGW Makefiles\" -DUA_ENABLE_AMALGAMATION=ON ..\nmingw32-make.exe\n\ngit clone http:\/\/code.qt.io\/qt\/qtopcua.git\ncd qtopcua\nmkdir build\ncd build\nset CPLUS_INCLUDE_PATH=c:\\path\\to\\open62541\\build\nset LIBRARY_PATH=c:\\path\\to\\open62541\\build\\bin\nqmake.exe ..\nmingw32-make.exe\nmingw32-make.exe install<\/pre><h3>Usage<\/h3><p>After successful completion of above steps Qt OpcUa will be available from your existing Qt5.10 installation. A documentation snapshot can be found <a href=\"https:\/\/doc-snapshots.qt.io\/qt5-dev\/qtopcua-index.html\" target=\"_blank\" rel=\"noopener\">here<\/a>.<\/p><p>The following &#8220;Hello Qt OpcUa&#8221; example shows how to read an attribute from a server (add QT += opcua to your .pro).<\/p><pre class=\"lang:default decode:true \">#include \n#include \n\nclass QOpcUaReader : public QObject\n{\nQ_OBJECT\n\npublic:\n    QOpcUaReader(QObject *parent);\n    bool init();\n    void handleStateChanged(QOpcUaClient::ClientState state);\n    void handleAttributeRead(QOpcUa::NodeAttributes attr);\n\nsignals:\n    void done();\n\nprivate:\n    QScopedPointer m_client;\n    QScopedPointer m_node;\n};\n\nQOpcUaReader::QOpcUaReader(QObject *parent)\n    : QObject(parent)\n{}\n\nbool QOpcUaReader::init()\n{\n    QOpcUaProvider p;\n    qDebug() &lt;&lt; \"Available backends:\" &lt;&lt; p.availableBackends();\n\n    if (p.availableBackends().size() == 0) {\n        qDebug() &lt;&lt; \"No backends found\";\n        return false;\n    }\n\n    m_client.reset(p.createClient(p.availableBackends()[0]));\n\n    if (!m_client) {\n        qDebug() &lt;&lt; \"Failed to create client\"; return false; } QObject::connect(m_client.data(), &amp;QOpcUaClient::stateChanged, this, &amp;QOpcUaReader::handleStateChanged); m_client-&gt;connectToEndpoint(QUrl(\"opc.tcp:\/\/opcua.demo-this.com:51210\/UA\/SampleServer\"));\n    return true;\n}\n\nvoid QOpcUaReader::handleStateChanged(QOpcUaClient::ClientState state)\n{\n    qDebug() &lt;&lt; \"Client state changed:\" &lt;&lt; state; switch(state) { case QOpcUaClient::ClientState::Connected: { m_node.reset(m_client-&gt;node(\"ns=0;i=84\"));\n        if (!m_node) {\n            qDebug() &lt;&lt; \"Failed to get node\"; emit done(); break; } QObject::connect(m_node.data(), &amp;QOpcUaNode::attributeRead, this, &amp;QOpcUaReader::handleAttributeRead); m_node-&gt;readAttributes(QOpcUa::NodeAttribute::BrowseName);\n        break;\n    }\n    case QOpcUaClient::Disconnected: {\n        emit done();\n        break;\n    }\n    default:\n        break;\n    }\n}\n\nvoid QOpcUaReader::handleAttributeRead(QOpcUa::NodeAttributes attr)\n{\n    qDebug() &lt;&lt; \"Signal for attributes:\" &lt;&lt; attr; if (m_node-&gt;attributeError(QOpcUa::NodeAttribute::BrowseName) == QOpcUa::UaStatusCode::Good)\n        qDebug() &lt;&lt; \"Browse name:\" &lt;&lt; m_node-&gt;attribute(QOpcUa::NodeAttribute::BrowseName).value().name;\n    else\n        qDebug() &lt;&lt; \"Failed to read attribute:\" &lt;&lt; m_node-&gt;attributeError(QOpcUa::NodeAttribute::BrowseName);\n\n    m_client-&gt;disconnectFromEndpoint();\n}\n\nint main(int argc, char *argv[])\n{\n    QCoreApplication a(argc, argv);\n    QOpcUaReader reader(&amp;a);\n    QObject::connect(&amp;reader, &amp;QOpcUaReader::done, &amp;a, &amp;QCoreApplication::quit);\n    if (!reader.init())\n        return 1;\n    return a.exec();\n}\n\n#include \"main.moc\"<\/pre><h3>Conclusion<\/h3><p>Most of the API envisioned for the Technology Preview is available. We are currently busy testing and polishing, as well as adding more comprehensive examples and improving the documentation. Please leave a comment or get in contact with\u00a0<a class=\"external-link\" href=\"mailto:\/\/opensource@basyskom.com\" rel=\"nofollow noopener\" target=\"_blank\">us<\/a>\u00a0if you have any questions or comments &#8211; you still have the chance to influence the final shape of the API.<\/p><p><img decoding=\"async\" class=\"alignleft wp-image-1277\" src=\"https:\/\/www.basyskom.de\/wp-content\/uploads\/2020\/02\/Qt_logo_space-01-01.png\" alt=\"Qt OpcUa\" width=\"94\" height=\"47\" srcset=\"https:\/\/www.basyskom.de\/wp-content\/uploads\/2020\/02\/Qt_logo_space-01-01.png 680w, https:\/\/www.basyskom.de\/wp-content\/uploads\/2020\/02\/Qt_logo_space-01-01-300x150.png 300w\" sizes=\"(max-width: 94px) 100vw, 94px\" \/><\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<\/div>\n\t\t","protected":false},"excerpt":{"rendered":"<p>basysKom has initiated Qt OpcUa which is a module offering support for the industrial communication standard OPC UA. This module has been contributed\u00a0by us to the Qt Project.\u00a0The\u00a0Qt OpcUa\u00a0API wraps existing OPC UA implementations. Currently, implementations for freeopcua and\u00a0open62541\u00a0are available.<\/p>","protected":false},"author":2,"featured_media":1557,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[2,7,8],"tags":[124,15,123],"class_list":["post-660","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog","category-general","category-qt","tag-opc-ua","tag-qt","tag-qt-opc-ua"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.basyskom.de\/en\/wp-json\/wp\/v2\/posts\/660","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.basyskom.de\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.basyskom.de\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.basyskom.de\/en\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.basyskom.de\/en\/wp-json\/wp\/v2\/comments?post=660"}],"version-history":[{"count":11,"href":"https:\/\/www.basyskom.de\/en\/wp-json\/wp\/v2\/posts\/660\/revisions"}],"predecessor-version":[{"id":7481,"href":"https:\/\/www.basyskom.de\/en\/wp-json\/wp\/v2\/posts\/660\/revisions\/7481"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.basyskom.de\/en\/wp-json\/wp\/v2\/media\/1557"}],"wp:attachment":[{"href":"https:\/\/www.basyskom.de\/en\/wp-json\/wp\/v2\/media?parent=660"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.basyskom.de\/en\/wp-json\/wp\/v2\/categories?post=660"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.basyskom.de\/en\/wp-json\/wp\/v2\/tags?post=660"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}