From dfc8e26b1f84c4b48d9247202fd3d4d0cb247825 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 18 Sep 2019 14:29:14 +0200 Subject: opcuaviewer: Add a command line parameter for the initial url Use QCommandLineParser to obtain the parameter. Change-Id: I770610df7046d7f4bd34ebb4d3fa2706e587439c Reviewed-by: Rainer Keller --- examples/opcua/opcuaviewer/main.cpp | 15 ++++++++++++++- examples/opcua/opcuaviewer/mainwindow.cpp | 3 ++- examples/opcua/opcuaviewer/mainwindow.h | 2 +- examples/opcua/opcuaviewer/mainwindow.ui | 3 --- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/examples/opcua/opcuaviewer/main.cpp b/examples/opcua/opcuaviewer/main.cpp index 56df0c7..b7df303 100644 --- a/examples/opcua/opcuaviewer/main.cpp +++ b/examples/opcua/opcuaviewer/main.cpp @@ -50,11 +50,24 @@ #include "mainwindow.h" #include +#include +#include int main(int argc, char **argv) { QApplication app(argc, argv); - MainWindow mainWindow; + QCoreApplication::setApplicationVersion(QLatin1String(QT_VERSION_STR)); + QCoreApplication::setApplicationName(QLatin1String("Qt OpcUa Viewer")); + + QCommandLineParser parser; + parser.addHelpOption(); + parser.addVersionOption(); + parser.addPositionalArgument(QLatin1String("url"), QLatin1String("The url to open.")); + parser.process(app); + + const auto positionalArguments = parser.positionalArguments(); + const auto initialUrl = positionalArguments.value(0, QLatin1String("opc.tcp://localhost:48010")); + MainWindow mainWindow(initialUrl.trimmed()); mainWindow.show(); return QCoreApplication::exec(); } diff --git a/examples/opcua/opcuaviewer/mainwindow.cpp b/examples/opcua/opcuaviewer/mainwindow.cpp index 137ffa8..3b47a27 100644 --- a/examples/opcua/opcuaviewer/mainwindow.cpp +++ b/examples/opcua/opcuaviewer/mainwindow.cpp @@ -112,12 +112,13 @@ static void messageHandler(QtMsgType type, const QMessageLogContext &context, co oldMessageHandler(type, context, msg); } -MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) +MainWindow::MainWindow(const QString &initialUrl, QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) , mOpcUaModel(new OpcUaModel(this)) , mOpcUaProvider(new QOpcUaProvider(this)) { ui->setupUi(this); + ui->host->setText(initialUrl); mainWindowGlobal = this; connect(ui->quitAction, &QAction::triggered, this, &QWidget::close); diff --git a/examples/opcua/opcuaviewer/mainwindow.h b/examples/opcua/opcuaviewer/mainwindow.h index 2f3d23d..346a555 100644 --- a/examples/opcua/opcuaviewer/mainwindow.h +++ b/examples/opcua/opcuaviewer/mainwindow.h @@ -67,7 +67,7 @@ class MainWindow : public QMainWindow { Q_OBJECT public: - explicit MainWindow(QWidget *parent = nullptr); + explicit MainWindow(const QString &initialUrl, QWidget *parent = nullptr); ~MainWindow(); Q_INVOKABLE void log(const QString &text, const QString &context, const QColor &color); void log(const QString &text, const QColor &color = Qt::black); diff --git a/examples/opcua/opcuaviewer/mainwindow.ui b/examples/opcua/opcuaviewer/mainwindow.ui index 429a4e4..e5be46a 100644 --- a/examples/opcua/opcuaviewer/mainwindow.ui +++ b/examples/opcua/opcuaviewer/mainwindow.ui @@ -68,9 +68,6 @@ - - opc.tcp://localhost:48010 - true -- cgit v1.2.3