swift QLPreviewPanel crash — NSConstraintBasedLayo

2019-08-22 19:41发布

问题:

I am trying to open a preview panel:

QLPreviewPanel.shared().makeKeyAndOrderFront(self) for a valid QLPreviewItem (url).

This works well for regular files, but crashes on folders and some specific urls, for example vnc internet connection files (.vnc).

The console error:

[Layout] Unable to simultaneously satisfy constraints: ( "", "", "", "", "" )

Will attempt to recover by breaking constraint

Set the NSUserDefault NSConstraintBasedLayoutVisualizeMutuallyExclusiveConstraints to YES to have -[NSWindow visualizeConstraints:] automatically called when this happens. And/or, set a symbolic breakpoint on LAYOUT_CONSTRAINTS_NOT_SATISFIABLE to catch this in the debugger.

Given the hint, I set NSConstraintBasedLayoutVisualizeMutuallyExclusiveConstraints to YES:

UserDefaults.standard.set(true, forKey: "NSConstraintBasedLayoutVisualizeMutuallyExclusiveConstraints") UserDefaults.standard.synchronize()

But this does not help at all. The exact same error is thrown. My application still crashes.

Adding NSConstraintBasedLayoutVisualizeMutuallyExclusiveConstraints as an argument did not work either. Nor did using an int (1) instead of a boolean (true) make any difference.

I am lost now, because my app crashes and I have no clue how to solve this. Any help to solve this would be highly appreciated.

update/addition

FWIW: I did not set any constraints myself, or make any other configuration. Just try to open a panel with using the default API. Code is working correctly for pdf and other kinds of regular files. Crashes on VNC, folders.