Skip to content

NewQFileDialog2 SelectedFiles() method panics #1188

@rootVIII

Description

@rootVIII

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/qt@v0.0.0-20200904063919-c0c124a5770d/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/qt@v0.0.0-20200904063919-c0c124a5770d/internal/internal.go:73 +0x486
github.com/therecipe/qt/internal.asyncCallbackHandler(0xc00022c6c6, 0x22)
        /Users/solsticenet/go/pkg/mod/github.com/therecipe/qt@v0.0.0-20200904063919-c0c124a5770d/internal/internal.go:109 +0x35
created by github.com/therecipe/qt/internal.InitProcess.func3
        /Users/solsticenet/go/pkg/mod/github.com/therecipe/qt@v0.0.0-20200904063919-c0c124a5770d/internal/internal.go:407 +0x108
exit status 2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions