Diálogo de archivo abierto simple de C ++ en Linux

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

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? -

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 -

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. -

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. -

Manera más sencilla: popen() on zenity --file-selection -

4 Respuestas

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

Yo escribí osdialog para este propósito. Ver osdialog_gtk2.c for an example using GTK+ 2.

contestado el 09 de mayo de 19 a las 21:05

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

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 or haz tu propia pregunta.