diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2019-09-18 14:29:14 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2019-09-18 17:06:31 +0200 |
commit | dfc8e26b1f84c4b48d9247202fd3d4d0cb247825 (patch) | |
tree | b93706eeb4128b68cdbecfba7cbf3e7107164f02 | |
parent | d2f0b3564af85e535cd599a395ca21f06437548c (diff) |
opcuaviewer: Add a command line parameter for the initial url
Use QCommandLineParser to obtain the parameter.
Change-Id: I770610df7046d7f4bd34ebb4d3fa2706e587439c
Reviewed-by: Rainer Keller <Rainer.Keller@qt.io>
-rw-r--r-- | examples/opcua/opcuaviewer/main.cpp | 15 | ||||
-rw-r--r-- | examples/opcua/opcuaviewer/mainwindow.cpp | 3 | ||||
-rw-r--r-- | examples/opcua/opcuaviewer/mainwindow.h | 2 | ||||
-rw-r--r-- | 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 <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> |