I was wondering if anyone could help me out on implementing a simple file open dialog in C++ in Ubuntu. I am using OpenGL for my GUI, but I would like the user to be able to select a file when the program loads. I have tried gtkmm and wxWidgets but they seem to be too complicated for what I want to do.
preguntado el 22 de septiembre de 13 a las 22:09
If you just need to select a file, then launch a separate program to do that. Like @Dummy00001 said in the comment, you can start
zenity --file-selection as a child process and read its stdout.
char filename; FILE *f = popen("zenity --file-selection", "r"); fgets(filename, 1024, f);
Or you can also write your own program to do the task. That way you can customize the UI as you wish.
Este proyecto puede ayudarte a: https://github.com/samhocevar/portable-file-dialogs
It uses the same idea described in these answers but it is architecture agnostic and for Unix it wraps zenity, kdialog ...
Here you have more complete code with zenity:
const char zenityP = "/usr/bin/zenity"; char Call; sprintf(Call,"%s --file-selection --modal --title=\"%s\" ", zenityP, "Select file"); FILE *f = popen(Call,"r"); fgets(Bufor, size, f); int ret=pclose(f); if(ret<0) perror("file_name_dialog()"); return ret==0;//return true if all is OK