summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/widgets/mainwindows/mdi/main.cpp12
-rw-r--r--examples/widgets/mainwindows/mdi/mainwindow.cpp18
-rw-r--r--examples/widgets/mainwindows/mdi/mainwindow.h2
3 files changed, 26 insertions, 6 deletions
diff --git a/examples/widgets/mainwindows/mdi/main.cpp b/examples/widgets/mainwindows/mdi/main.cpp
index ab5f9b1480..d454f52e28 100644
--- a/examples/widgets/mainwindows/mdi/main.cpp
+++ b/examples/widgets/mainwindows/mdi/main.cpp
@@ -39,6 +39,8 @@
****************************************************************************/
#include <QApplication>
+#include <QCommandLineParser>
+#include <QCommandLineOption>
#include "mainwindow.h"
@@ -47,7 +49,17 @@ int main(int argc, char *argv[])
Q_INIT_RESOURCE(mdi);
QApplication app(argc, argv);
+ QCoreApplication::setApplicationVersion(QT_VERSION_STR);
+ QCommandLineParser parser;
+ parser.setApplicationDescription("Qt MDI Example");
+ parser.addHelpOption();
+ parser.addVersionOption();
+ parser.addPositionalArgument("file", "The file to open.");
+ parser.process(app);
+
MainWindow mainWin;
+ foreach (const QString &fileName, parser.positionalArguments())
+ mainWin.openFile(fileName);
mainWin.show();
return app.exec();
}
diff --git a/examples/widgets/mainwindows/mdi/mainwindow.cpp b/examples/widgets/mainwindows/mdi/mainwindow.cpp
index ab61dd6561..d58a47e669 100644
--- a/examples/widgets/mainwindows/mdi/mainwindow.cpp
+++ b/examples/widgets/mainwindows/mdi/mainwindow.cpp
@@ -95,16 +95,22 @@ void MainWindow::open()
return;
}
- MdiChild *child = createMdiChild();
- if (child->loadFile(fileName)) {
+ if (openFile(fileName))
statusBar()->showMessage(tr("File loaded"), 2000);
- child->show();
- } else {
- child->close();
- }
}
}
+bool MainWindow::openFile(const QString &fileName)
+{
+ MdiChild *child = createMdiChild();
+ const bool succeeded = child->loadFile(fileName);
+ if (succeeded)
+ child->show();
+ else
+ child->close();
+ return succeeded;
+}
+
void MainWindow::save()
{
if (activeMdiChild() && activeMdiChild()->save())
diff --git a/examples/widgets/mainwindows/mdi/mainwindow.h b/examples/widgets/mainwindows/mdi/mainwindow.h
index b24cdd4db1..ef86c68602 100644
--- a/examples/widgets/mainwindows/mdi/mainwindow.h
+++ b/examples/widgets/mainwindows/mdi/mainwindow.h
@@ -59,6 +59,8 @@ class MainWindow : public QMainWindow
public:
MainWindow();
+ bool openFile(const QString &fileName);
+
protected:
void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE;