I solved my problem, according to macOS Swift QuickLook Warning: setDelegate and setDataSource called while the panel has no controller.
first of all, to start opening the file, I had
@objc func previewFile(_ sender: Any) {
let panel = QLPreviewPanel.shared()
panel?.dataSource = self
panel?.delegate = self
panel?.makeKeyAndOrderFront(nil)
}
The panel dataSource and delegate dont't have to be implemented there, but in the following functions:
override func beginPreviewPanelControl(_ panel: QLPreviewPanel!) {
print("beginPreviewPanelController \(panel)")
panel.dataSource = self
panel.delegate = self
}
override func endPreviewPanelControl(_ panel: QLPreviewPanel!) {
print("endPreviewPanelController \(panel)")
panel.dataSource = nil
panel.delegate = nil
}
after that, I used an URL by calling URL(string: ...). That was the reason of the problem. I had to use URL(fileURLWithPath: ...)
hoping this will help