summaryrefslogtreecommitdiffstats
path: root/examples/opengl
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2023-09-12 15:32:51 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2023-09-18 22:28:42 +0000
commit6c9ecf98e1624c3eb359e76563c92429ea9c6aa1 (patch)
treeb645f12ca769401abae1c8c439186e80a1e59d99 /examples/opengl
parent734db610c3db3f00775d518b63d94695a2654389 (diff)
hellogl2 example: Decouple mainwindow from window
The circular dependency cannot be ported to the corresponding Python example. Task-number: PYSIDE-2206 Pick-to: 6.5 Change-Id: I031b3fffdd7bd677d2fc55e132975a65f66ad128 Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io> (cherry picked from commit 62eaaeb4f58388dc56cb1b23beae892e2fd6df89) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'examples/opengl')
-rw-r--r--examples/opengl/hellogl2/mainwindow.cpp2
-rw-r--r--examples/opengl/hellogl2/window.cpp19
-rw-r--r--examples/opengl/hellogl2/window.h4
3 files changed, 16 insertions, 9 deletions
diff --git a/examples/opengl/hellogl2/mainwindow.cpp b/examples/opengl/hellogl2/mainwindow.cpp
index 4ec8fcb8b1..5ee2b738c2 100644
--- a/examples/opengl/hellogl2/mainwindow.cpp
+++ b/examples/opengl/hellogl2/mainwindow.cpp
@@ -23,7 +23,7 @@ MainWindow::MainWindow()
void MainWindow::onAddNew()
{
if (!centralWidget())
- setCentralWidget(new Window(this));
+ setCentralWidget(new Window);
else
QMessageBox::information(this, tr("Cannot Add New Window"),
tr("Already occupied. Undock first."));
diff --git a/examples/opengl/hellogl2/window.cpp b/examples/opengl/hellogl2/window.cpp
index 2f9c33b24e..5a7ddf826f 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;
diff --git a/examples/opengl/hellogl2/window.h b/examples/opengl/hellogl2/window.h
index 3fd64086ec..edbd643ae2 100644
--- a/examples/opengl/hellogl2/window.h
+++ b/examples/opengl/hellogl2/window.h
@@ -10,14 +10,13 @@ QT_FORWARD_DECLARE_CLASS(QSlider)
QT_FORWARD_DECLARE_CLASS(QPushButton)
class GLWidget;
-class MainWindow;
class Window : public QWidget
{
Q_OBJECT
public:
- Window(MainWindow *mw);
+ Window();
protected:
void keyPressEvent(QKeyEvent *event) override;
@@ -35,7 +34,6 @@ private:
QSlider *ySlider;
QSlider *zSlider;
QPushButton *dockBtn;
- MainWindow *mainWindow;
};
#endif