qt icon indicating copy to clipboard operation
qt copied to clipboard

NewQFileDialog2 SelectedFiles() method panics

Open rootVIII opened this issue 3 years ago • 2 comments

I'm on MacOS Big Sur. Everything works great until the OK button is pressed and I try to print the file path. My example looks very similar to what you have in your example.

// OpenPDFInput opens the PDF that needs to be inverted.
func (gui *GUI) OpenPDFInput() {
	fileDialog := widgets.NewQFileDialog2(gui.Window, "Open PDF", gui.UserInfo.HomeDir, "")
	fileDialog.SetAcceptMode(widgets.QFileDialog__AcceptOpen)
	fileDialog.SetFileMode(widgets.QFileDialog__ExistingFile)
	fileDialog.SetMimeTypeFilters([]string{"application/pdf"})
	if fileDialog.Exec() == int(widgets.QDialog__Accepted) {
		fmt.Printf("%v\n", fileDialog.SelectedFiles()[0])
	}
}

As soon as fileDialog.SelectedFiles() runs, I get a panic. I am not sure why though. I may possibly be doing something wrong, but my example is very similar to yours (and everything else in my program works fine). Here is the error:

panic: interface conversion: interface {} is []interface {}, not []string

goroutine 34 [running]:
github.com/therecipe/qt/widgets.(*QFileDialog).SelectedFiles(0xc0000d8900, 0x1, 0x1, 0x1)
        /Users/solsticenet/go/pkg/mod/github.com/therecipe/[email protected]/widgets/widgets.go:13192 +0x1b4
main.(*GUI).OpenPDFInput(0xc0001122c0)
        /Users/solsticenet/go/src/github.com/rootVIII/pdfinverter/gui.go:35 +0x26f
main.(*GUI).RunApp.func1(0x0)
        /Users/solsticenet/go/src/github.com/rootVIII/pdfinverter/gui.go:69 +0x2a
reflect.Value.call(0x5118220, 0xc0000a86b0, 0x13, 0x539214e, 0x4, 0xc00020f880, 0x1, 0x1, 0x81, 0x686ed60, ...)
        /usr/local/go/src/reflect/value.go:475 +0x8c7
reflect.Value.Call(0x5118220, 0xc0000a86b0, 0x13, 0xc00020f880, 0x1, 0x1, 0x686ed60, 0x81, 0x0)
        /usr/local/go/src/reflect/value.go:336 +0xb9
github.com/therecipe/qt/internal.handleCallback(0xc00022c6c6, 0x22, 0x1, 0x0)
        /Users/solsticenet/go/pkg/mod/github.com/therecipe/[email protected]/internal/internal.go:73 +0x486
github.com/therecipe/qt/internal.asyncCallbackHandler(0xc00022c6c6, 0x22)
        /Users/solsticenet/go/pkg/mod/github.com/therecipe/[email protected]/internal/internal.go:109 +0x35
created by github.com/therecipe/qt/internal.InitProcess.func3
        /Users/solsticenet/go/pkg/mod/github.com/therecipe/[email protected]/internal/internal.go:407 +0x108
exit status 2

rootVIII avatar Nov 14 '20 20:11 rootVIII

Well I ended up using this instead... I guess it's okay:

path := widgets.QFileDialog_GetOpenFileName(gui.Window, "Open PDF", gui.UserInfo.HomeDir, "(*.pdf)", "", widgets.QFileDialog__DontUseNativeDialog)
fmt.Println(path)

rootVIII avatar Nov 14 '20 23:11 rootVIII

I personally still have this issue. @rootVIII solution works, but it would be great if this is fixed in the futur.

nakrule avatar Sep 14 '21 08:09 nakrule