QTOpcUa -- connectToEndPoint Error
-
Dear all,
I'm probably doing something stupid. I'm trying the first time to connect to OPC UA server.
I'm following the below tutorial from QT:
https://www.youtube.com/watch?v=p4MNmzkxsq0&t=2109s@ 30 min he is writting :
m_client->connectToEndpoint(QUrl("opc.tcp://localhost:4840"));
When I try to, I always get the next error:
error: no viable conversion from 'QUrl' to 'const QOpcUaEndpointDescription'
Can somebody explain me what could be wrong? So I can learn from it?
Below the code .#ifndef MACHINESTATE_H #define MACHINESTATE_H #include <QObject> #include <QScopedPointer> #include <QtOpcUa> class machinestate : public QObject { Q_OBJECT public: explicit machinestate(QObject *parent = nullptr); signals: public slots: void onStateChanged(QOpcUaClient::ClientState state); private: QScopedPointer<QOpcUaClient> m_client; QScopedPointer<QOpcUaNode> m_statusNode; }; #endif // MACHINESTATE_H
#include "machinestate.h" #include <QDebug> #include <QUrl> machinestate::machinestate(QObject *parent) : QObject(parent) { QOpcUaProvider provider; qDebug() << provider.availableBackends(); m_client.reset(provider.createClient("open62541")); qDebug() << m_client.data(); connect(m_client.data(), &QOpcUaClient::stateChanged, this, &machinestate::onStateChanged); m_client->connectToEndpoint(QUrl("opc.tcp://localhost:4840")); } void machinestate::onStateChanged(QOpcUaClient::ClientState state) { qDebug() << state; }
I'm using Qt5.13.0.
Thanks in advance,
Kind regards. -
@TMJJ001 said in QTOpcUa -- connectToEndPoint Error:
error: no viable conversion from 'QUrl' to 'const QOpcUaEndpointDescription'
The error tells you what is wrong: QUrl cannot be implicitly converted to QOpcUaEndpointDescription.
https://doc-snapshots.qt.io/qtopcua/qopcuaclient.html#connectToEndpoint takes a QOpcUaEndpointDescription not QUrl.
Create a QOpcUaEndpointDescription and pass it to connectToEndpoint. -
Do not use QUrl.
m_client->connectToEndpoint("opc.tcp://localhost:4840"); -
@thisisseven it will fail also! As @jsulm said QOpcUaClient::connectToEndpoint takes a QOpcUaEndpointDescription
-
@LeLev
QOpcUaProvider *provider=new QOpcUaProvider(this);
m_client = provider->createClient("open62541");
if(!m_client){
qDebug()<<"error";
}
m_client->connectToEndpoint("opc.tcp://localhost:4840");Check out the article below.
https://doc-snapshots.qt.io/qtopcua/qtopcua-opcuaviewer-example.html -