gpt4 book ai didi

c - 错误 : ‘parent_window’ undeclared

转载 作者:太空宇宙 更新时间:2023-11-04 07:16:28 26 4
gpt4 key购买 nike

我在用 C 语言编译程序时遇到问题。我想使用以下代码运行简单的文件选择器:

#include <gtk/gtk.h>

int main( int argc, char *argv[])
{
GtkWidget *dialog;

gtk_init(&argc, &argv);

dialog = gtk_file_chooser_dialog_new ("Open File",parent_window,action,_("_Cancel"),GTK_RESPONSE_CANCEL,_("_Open"),GTK_RESPONSE_ACCEPT,NULL);

if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
{
char *filename;
GtkFileChooser *chooser = GTK_FILE_CHOOSER (dialog);
filename = gtk_file_chooser_get_filename (chooser);
open_file (filename);
g_free (filename);
}

gtk_widget_destroy (dialog);

gtk_main();

return 0;
}

我使用该命令编译它:

gcc -o s5 s5.c `pkg-config --libs --cflags gtk+-3.0`

我得到了错误:

s5.c:10:39: error: ‘parent_window’ undeclared (first use in this function)
parent_window,
^
s5.c:10:39: note: each undeclared identifier is reported only once for each function it appears in
s5.c:11:39: error: ‘action’ undeclared (first use in this function)
action,
^
s5.c:16:39: warning: passing argument 4 of ‘gtk_file_chooser_dialog_new’ makes pointer from integer without a cast [enabled by default]
NULL);
^
In file included from /usr/include/gtk-3.0/gtk/gtk.h:99:0,
from s5.c:1:
/usr/include/gtk-3.0/gtk/gtkfilechooserdialog.h:63:12: note: expected ‘const gchar *’ but argument is of type ‘int’
GtkWidget *gtk_file_chooser_dialog_new (const gchar *title,
^

我尝试用 GTK+ 2 做同样的事情,但也遇到了同样的错误;/

最佳答案

对于那些想要从 gtk+ 示例运行文件选择的人来说,这是答案:

#include <gtk/gtk.h>

int main( int argc, char *argv[]){

//dialog variable
GtkWidget *dialog;

gtk_init(&argc, &argv);

//Define dialog
dialog = gtk_file_chooser_dialog_new ("Open File",NULL,GTK_FILE_CHOOSER_ACTION_OPEN,GTK_STOCK_CANCEL,GTK_RESPONSE_CANCEL,GTK_STOCK_OPEN,GTK_RESPONSE_ACCEPT,NULL);

//If file was choosen
if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT){
char *filename;
filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
printf("Selected file: %s\n", filename);
} else {
gtk_widget_destroy (dialog);
return 0;
}


gtk_main();
}

要编译你需要使用的命令:

gcc -o s6 s6.c `pkg-config --libs --cflags gtk+-2.0`

关于c - 错误 : ‘parent_window’ undeclared,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24249238/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com