summaryrefslogtreecommitdiffstats
path: root/examples/opengl/hellogl2/window.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'examples/opengl/hellogl2/window.cpp')
-rw-r--r--examples/opengl/hellogl2/window.cpp19
1 files changed, 14 insertions, 5 deletions
diff --git a/examples/opengl/hellogl2/window.cpp b/examples/opengl/hellogl2/window.cpp
index 2f9c33b24e0..5a7ddf826fd 100644
--- a/examples/opengl/hellogl2/window.cpp
+++ b/examples/opengl/hellogl2/window.cpp
@@ -1,9 +1,8 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-#include "glwidget.h"
#include "window.h"
-#include "mainwindow.h"
+#include "glwidget.h"
#include <QSlider>
#include <QVBoxLayout>
#include <QHBoxLayout>
@@ -11,9 +10,18 @@
#include <QPushButton>
#include <QApplication>
#include <QMessageBox>
+#include <QMainWindow>
+
+static QMainWindow *findMainWindow()
+{
+ for (auto *w : QApplication::topLevelWidgets()) {
+ if (auto *mw = qobject_cast<QMainWindow *>(w))
+ return mw;
+ }
+ return nullptr;
+}
-Window::Window(MainWindow *mw)
- : mainWindow(mw)
+Window::Window()
{
glWidget = new GLWidget;
@@ -77,7 +85,8 @@ void Window::dockUndock()
void Window::dock()
{
- if (!mainWindow->isVisible()) {
+ auto *mainWindow = findMainWindow();
+ if (mainWindow == nullptr || !mainWindow->isVisible()) {
QMessageBox::information(this, tr("Cannot Dock"),
tr("Main window already closed"));
return;