Skip to content

Instantly share code, notes, and snippets.

@torarnv
Created March 3, 2023 11:03
Show Gist options
  • Save torarnv/7bbd31d9879c390071d5aa0e9a1f2af1 to your computer and use it in GitHub Desktop.
Save torarnv/7bbd31d9879c390071d5aa0e9a1f2af1 to your computer and use it in GitHub Desktop.
diff --git i/src/plugins/platforms/cocoa/qcocoawindow.mm w/src/plugins/platforms/cocoa/qcocoawindow.mm
index cb813114ef8..be2efdae110 100644
--- i/src/plugins/platforms/cocoa/qcocoawindow.mm
+++ w/src/plugins/platforms/cocoa/qcocoawindow.mm
@@ -134,16 +134,18 @@ void QCocoaWindow::initialize()
if (!m_view)
m_view = [[QNSView alloc] initWithCocoaWindow:this];
- // Compute the initial geometry based on the geometry set on the
- // QWindow. This geometry has already been reflected to the
- // QPlatformWindow in the constructor, so to ensure that the
- // resulting setGeometry call does not think the geometry has
- // already been applied, we reset the QPlatformWindow's view
- // of the geometry first.
- auto initialGeometry = QPlatformWindow::initialGeometry(window(),
- windowGeometry(), defaultWindowWidth, defaultWindowHeight);
- QPlatformWindow::d_ptr->rect = QRect();
- setGeometry(initialGeometry);
+ if (!isForeignWindow()) {
+ // Compute the initial geometry based on the geometry set on the
+ // QWindow. This geometry has already been reflected to the
+ // QPlatformWindow in the constructor, so to ensure that the
+ // resulting setGeometry call does not think the geometry has
+ // already been applied, we reset the QPlatformWindow's view
+ // of the geometry first.
+ auto initialGeometry = QPlatformWindow::initialGeometry(window(),
+ windowGeometry(), defaultWindowWidth, defaultWindowHeight);
+ QPlatformWindow::d_ptr->rect = QRect();
+ setGeometry(initialGeometry);
+ }
recreateWindowIfNeeded();
@@ -1468,7 +1470,7 @@ void QCocoaWindow::recreateWindowIfNeeded()
const bool shouldBeContentView = !parentWindow
&& !((type & Qt::SubWindow) == Qt::SubWindow)
- && !isEmbeddedView;
+ && !isEmbeddedView && !isForeignWindow();
if (isContentView() != shouldBeContentView)
recreateReason |= ContentViewChanged;
@conradjones
Copy link

@pmogylevskyi are the builtin Apple Audio Units working for you in your app ? I am able to load / view NSView for most third party ones but some of the apples ones crash AUBandPass being the first example.
It is definitely to do with using QWindow::fromWinId() + QWidget::createWindowContainer() if I just do QWindow::fromWinId() and show that window it works fine, as soon as I add QWidget::createWindowContainer() to embed in a widget hierarchy (we need preset selection etc right) it crashes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment