Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NewQFileDialog2 SelectedFiles() method panics #1188

Open
rootVIII opened this issue Nov 14, 2020 · 2 comments · May be fixed by #1207
Open

NewQFileDialog2 SelectedFiles() method panics #1188

rootVIII opened this issue Nov 14, 2020 · 2 comments · May be fixed by #1207

Comments

@rootVIII
Copy link

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
Copy link
Author

rootVIII commented Nov 14, 2020

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)

@nakrule
Copy link

nakrule commented Sep 14, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants