Diálogo de archivo abierto simple de C ++ en Linux
Frecuentes
Visto 7,876 veces
8
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.
4 Respuestas
7
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[1024];
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.
Respondido 22 Feb 19, 12:02
1
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 ...
Respondido 30 Jul 21, 23:07
0
Here you have more complete code with zenity:
const char zenityP[] = "/usr/bin/zenity";
char Call[2048];
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
contestado el 13 de mayo de 20 a las 11:05
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas c++ linux file dialog or haz tu propia pregunta.
gtkmm and wxWidgets both come with premade file chooser dialogs. Does it get much simpler than that? In what way are those too complicated for you? - us2012
what I mean is that both openGl and gtk need their own main loops to be running at the same time, and I don't know how to integrate both of them. thanks for the response - user2805119
Why "at the same time"? You say you need to select a file when the program loads so theoretically you could even have a separate gtkmm program for the file chooser that then passes the file name as a command line parameter to your OpenGL app. - us2012
oh I mean that the user should be able to load a file when it starts but also at any time during the use of the program. but that does make sense. - user2805119
Manera más sencilla:
popen()
onzenity --file-selection
- Dummy00001