summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/opcua/opcuaviewer/main.cpp15
-rw-r--r--examples/opcua/opcuaviewer/mainwindow.cpp3
-rw-r--r--examples/opcua/opcuaviewer/mainwindow.h2
-rw-r--r--examples/opcua/opcuaviewer/mainwindow.ui3
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 <QApplication>
+#include <QCommandLineParser>
+#include <QCommandLineOption>
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 @@
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="host">
- <property name="text">
- <string>opc.tcp://localhost:48010</string>
- </property>
<property name="clearButtonEnabled">
<bool>true</bool>
</property>