gpt4 book ai didi

c - 错误: unknown type name ‘WebKitWebFrame’

转载 作者:行者123 更新时间:2023-11-30 14:51:13 25 4
gpt4 key购买 nike

我正在尝试构建一个带有网址栏的浏览器。 URL栏需要反射(reflect)浏览器中的任何导航更改,文档建议使用navigation-policy-decision-requested;回调需要 5 个参数,类型为 WebkitWebView、WebKitWebFrame、WebKitNetworkRequest、WebKitNavigationAction、webKitPolicyDecision 和 gpointer。

当我尝试编译时,我收到几个变体错误“错误:未知类型名称”。除了 WebkitWebView 之外,列出的所有内容都会发生这种情况。我知道我包含了 webkit2.h。我知道我尝试过显式定义,例如通过初始化 WebKitWebFrame,但它所做的只是产生更多错误。类型还没有定义吗?或者我必须自己定义它们?

编辑:我之前测试的计算机上的 Wifi 连接非常弱,因此我无法提供代码或编译输出。抱歉。

main.c

static void uriUpdateCb(WebKitWebView* web_view, WebKitWebFrame* frame, WebkitNetworkRequest* request, WebkitWebNavigationAction* navigation_action, WebkitWebPolicyDecision* policy_decision, gpointer user_data){
const gchar* uri = webkit_network_request_get_uri(request);
char* file_type = strchr(uri, '.');
if(file_type && (!strcmp(file_type, ".pdf") || !strcmp(file_type, ".db") || !strcmp(file_type, ".exe") || !strcmp(file_type, ".deb") || !strcmp(file_type, ".rpm") || !strcmp(file_type, ".dmg"))){
// note to self: replace above if statement with a loop and a file that contains these extensions
webkit_web_policy_decision_download(policy_decision);
}
else{
webkit_web_policy_decision_use(policy_decision);
gtk_entry_set_text(user_data, uri);
}
}

window.h(控制webkitWebview)

g_signal_connect(webView, "navigation-policy-decision-requested", G_CALLBACK(uriUpdateCb), url_bar);

callbacks.h(定义)

static void uriUpdateCb(WebKitWebView* web_view, WebKitWebFrame* frame, WebkitNetworkRequest* request, WebkitWebNavigationAction* navigation_action, WebkitWebPolicyDecision* policy_decision, gpointer user_data);

编译错误

In file included from main.c:35:0:
callbacks.h:4:50: error: unknown type name ‘WebKitWebFrame’
static void uriUpdateCb(WebKitWebView* web_view, WebKitWebFrame* frame, WebkitNet
^
callbacks.h:4:73: error: unknown type name ‘WebkitNetworkRequest’
atic void uriUpdateCb(WebKitWebView* web_view, WebKitWebFrame* frame, WebkitNetwo
^
callbacks.h:4:104: error: unknown type name ‘WebkitWebNavigationAction’
View* web_view, WebKitWebFrame* frame, WebkitNetworkRequest* request, WebkitWebNa
^
In file included from main.c:35:0:
callbacks.h:4:150: error: unknown type name ‘WebkitWebPolicyDecision’
etworkRequest* request, WebkitWebNavigationAction* navigation_action, WebkitWebPo
^
In file included from /usr/include/glib-2.0/gobject/gobject.h:28:0,
from /usr/include/glib-2.0/gobject/gbinding.h:29,
from /usr/include/glib-2.0/glib-object.h:23,
from /usr/include/glib-2.0/gio/gioenums.h:28,
from /usr/include/glib-2.0/gio/giotypes.h:28,
from /usr/include/glib-2.0/gio/gio.h:26,
from /usr/include/gtk-3.0/gdk/gdkapplaunchcontext.h:28,
from /usr/include/gtk-3.0/gdk/gdk.h:32,
from /usr/include/gtk-3.0/gtk/gtk.h:30,
from main.c:29:
window.h: In function ‘create_window’:
window.h:56:81: error: ‘uriUpdateCb’ undeclared (first use in this function)
l_connect(webView, "navigation-policy-decision-requested", G_CALLBACK(uriUpdateCb
^
/usr/include/glib-2.0/gobject/gsignal.h:475:60: note: in definition of macro ‘g_signal_connect’
g_signal_connect_data ((instance), (detailed_signal), (c_handler), (data), NU
^
window.h:56:70: note: in expansion of macro ‘G_CALLBACK’
g_signal_connect(webView, "navigation-policy-decision-requested", G_CALLBACK(u
^
window.h:56:81: note: each undeclared identifier is reported only once for each function it appears in
l_connect(webView, "navigation-policy-decision-requested", G_CALLBACK(uriUpdateCb
^
/usr/include/glib-2.0/gobject/gsignal.h:475:60: note: in definition of macro ‘g_signal_connect’
g_signal_connect_data ((instance), (detailed_signal), (c_handler), (data), NU
#include <gtk/gtk.h>
#include <string.h>
#include <gtk/gtk.h>
#include <string.h>
#include <stdio.h>
#include <webkit2/webkit2.h>

// window.h
int create_window(){

// Create an 800x600 window that will contain the browser instance
GtkWidget *main_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size(GTK_WINDOW(main_window), 800, 600);

// create the tab manager
GtkWidget *notebook = gtk_notebook_new();

GtkWidget *label = gtk_label_new ("test");

// create the gtk box that'll set the layout and put box in window
GtkWidget *box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5);


gtk_notebook_append_page(GTK_NOTEBOOK (notebook), box, label);


gtk_container_add(GTK_CONTAINER(main_window), GTK_WIDGET(notebook));

GtkWidget *grid = gtk_grid_new();
gtk_container_add(GTK_CONTAINER(box), GTK_WIDGET(grid));

// create url_bar and add to grid

GtkWidget *back_button = gtk_button_new_with_label("Back");
GtkWidget *forward_button = gtk_button_new_with_label("Forward");
GtkWidget *stop_connection_button = gtk_button_new_with_label("Stop");

GtkEntryBuffer *buf = gtk_entry_buffer_new("about:blank", 12);
GtkWidget *url_bar = gtk_entry_new_with_buffer(buf);

gtk_grid_attach(GTK_GRID(grid), back_button, 0, 0, 1, 1);
gtk_grid_attach(GTK_GRID(grid), forward_button, 1, 0, 1, 1);
^
window.h:56:70: note: in expansion of macro ‘G_CALLBACK’
g_signal_connect(webView, "navigation-policy-decision-requested", G_CALLBACK(u
^
main.c: At top level:
main.c:107:50: error: unknown type name ‘WebKitWebFrame’
static void uriUpdateCb(WebKitWebView* web_view, WebKitWebFrame* frame, WebkitNet
^
main.c:107:73: error: unknown type name ‘WebkitNetworkRequest’
atic void uriUpdateCb(WebKitWebView* web_view, WebKitWebFrame* frame, WebkitNetwo
^
main.c:107:104: error: unknown type name ‘WebkitWebNavigationAction’
View* web_view, WebKitWebFrame* frame, WebkitNetworkRequest* request, WebkitWebNa
^
main.c:107:150: error: unknown type name ‘WebkitWebPolicyDecision’
etworkRequest* request, WebkitWebNavigationAction* navigation_action, WebkitWebPo

最佳答案

WebKitWebFrame 和 WebKitNetworkRequest 是来自过时的 webkitgtk-1.0 和 webkitgtk-3.0 API 的类型,但由于您包含了 webkit2.h,所以很明显您正在尝试使用现代的 webkit2gtk-4.0 API(正如您应该的那样)。您可能正在查看旧 API 的文档。 Here is the modern documentation.

您无需听取导航策略决策即可获取 URL。只需通过连接到notify::uri 信号来查找WebKitWebView::uri 的属性更改即可。如果您不确定如何执行此操作,请查找 g_signal_connect() 的文档。

关于c - 错误: unknown type name ‘WebKitWebFrame’ ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48455278/

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