作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想从条目中设置 var pid,但收到以下警告:
gtk.c:7:6: warning: assignment makes integer from pointer without a cast [enabled by default].
如何创建 var pid == 条目?这是非常重要的,因为这个程序将向我们要输入 id (pid) 的进程发送信号。
#include <gtk/gtk.h>
#include <stdlib.h>
pid_t pid;
void sendSighup(GtkWidget *widget,GtkWidget *entry, gpointer label) {
pid = gtk_entry_get_text(GTK_ENTRY(entry));
kill(pid,SIGHUP);
}
void sendSigint(GtkWidget *widget, gpointer label) {
kill(pid,SIGINT);
}
void sendSigkill(GtkWidget *widget, gpointer label) {
kill(pid,SIGKILL);
}
void sendSigterm(GtkWidget *widget, gpointer label) {
kill(pid,SIGTERM);
}
void sendSigstop(GtkWidget *widget, gpointer label) {
kill(pid,SIGSTOP);
}
accept_clicked (GtkButton *button, GObject *context_object)
{
GtkLabel *accept_lable1 = g_object_get_data (context_object, "label1");
GtkEntry *accept_entry = g_object_get_data (context_object, "entry");
const char *entry_in = gtk_entry_get_text (accept_entry);
gtk_label_set_text (accept_lable1, entry_in);
}
int main( int argc, char *argv[])
{
GtkWidget *window;
GtkWidget *frame;
GtkWidget *table;
GtkWidget *button1;
GtkWidget *button2;
GtkWidget *button3;
GtkWidget *button4;
GtkWidget *button5;
GtkWidget *quit;
GtkWidget *set;
GtkWidget *vseparator;
GtkWidget *entry;
GtkWidget *label;
GtkWidget *label1;
GtkWidget *label2;
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "Send Signal");
gtk_window_set_default_size(GTK_WINDOW(window), 300, 250);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
frame = gtk_fixed_new();
gtk_container_add(GTK_CONTAINER(window), frame);
button1 = gtk_button_new_with_label("Sighup");
gtk_fixed_put(GTK_FIXED(frame), button1, 8, 15);
gtk_widget_set_size_request(button1, 80, 35);
button2 = gtk_button_new_with_label("Sigint");
gtk_fixed_put(GTK_FIXED(frame), button2, 8, 60);
gtk_widget_set_size_request(button2, 80, 35);
button3 = gtk_button_new_with_label("Sigkill");
gtk_fixed_put(GTK_FIXED(frame), button3, 8, 105);
gtk_widget_set_size_request(button3, 80, 35);
button4 = gtk_button_new_with_label("Sigterm");
gtk_fixed_put(GTK_FIXED(frame), button4, 8, 150);
gtk_widget_set_size_request(button4, 80, 35);
button5 = gtk_button_new_with_label("Sigstop");
gtk_fixed_put(GTK_FIXED(frame), button5, 8, 195);
gtk_widget_set_size_request(button5, 80, 35);
set = gtk_button_new_with_label ("Set");
gtk_fixed_put(GTK_FIXED(frame), set, 200, 80);
gtk_widget_set_size_request(set, 80, 35);
quit = gtk_button_new_with_label("Quit");
gtk_fixed_put(GTK_FIXED(frame), quit, 200, 195);
gtk_widget_set_size_request(quit, 80, 35);
vseparator = gtk_vseparator_new();
gtk_widget_set_size_request(vseparator, 10, 240);
gtk_fixed_put(GTK_FIXED(frame), vseparator, 95, 5);
label = gtk_label_new("Enter PID:");
gtk_fixed_put(GTK_FIXED(frame), label, 165, 20);
label2 = gtk_label_new("PID:");
gtk_fixed_put(GTK_FIXED(frame), label2, 110, 89);
label1 = gtk_label_new("0000");
gtk_fixed_put(GTK_FIXED(frame), label1, 140, 89);
entry = gtk_entry_new();
gtk_fixed_put(GTK_FIXED(frame), entry, 120, 40);
gtk_widget_grab_focus(entry);
g_object_set_data(G_OBJECT(set), "label1", label1);
g_object_set_data(G_OBJECT(set), "entry", entry);
g_signal_connect(GTK_BUTTON (set), "clicked",
G_CALLBACK (accept_clicked), set);
g_signal_connect_swapped(G_OBJECT(window), "destroy",
G_CALLBACK(gtk_main_quit), NULL);
g_signal_connect(button1, "clicked",
G_CALLBACK(sendSighup), NULL);
g_signal_connect(button2, "clicked",
G_CALLBACK(sendSigint), NULL);
g_signal_connect(button3, "clicked",
G_CALLBACK(sendSigkill), NULL);
g_signal_connect(button4, "clicked",
G_CALLBACK(sendSigterm), NULL);
g_signal_connect(button5, "clicked",
G_CALLBACK(sendSigstop), NULL);
g_signal_connect(G_OBJECT(quit), "clicked",
G_CALLBACK(gtk_main_quit), G_OBJECT(window));
gtk_widget_show_all(window);
gtk_widget_show(entry);
gtk_widget_show(label);
gtk_main();
return 0;
}
最佳答案
关于c - 如何从 gtk_entry 设置变量值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24326778/
我想做一个 g_signal_connect 来捕获一个在 gtk_entry 小部件中单击鼠标。 像这样: entry = gtk_entry_new ( ); gtk_box_pack_end (
我正在尝试创建一个当用户从组合框中选择特定条目时弹出的对话框,它应该记录用户输入并做出相应的 react 。 到目前为止,这是我的代码: void add_new_set(GtkWidget entr
我想从条目中设置 var pid,但收到以下警告: gtk.c:7:6: warning: assignment makes integer from pointer without a cast [
我需要编写一个函数来验证用户在 gtk 输入字段中键入的设备名称。 设备必须采用以下形式: "/dev/video + one digits" ( e.g. /dev/video1 ) 为此我做了一个
我是一名优秀的程序员,十分优秀!