1
我正在用C++編寫一個使用GTK +(不是gtkmm)的應用程序,因此我需要使用g ++編譯器進行編譯。是否可以用g ++編譯器編譯GTK +應用程序? GTK +和庫與g ++編譯器兼容嗎?使用G ++編譯器編譯GTK +應用程序
我試圖嵌入GTK +函數調用的類象如下:
#include <gtk/gtk.h>
class LoginWindow
{
public:
LoginWindow();
void on_window_destroy(GtkObject *object, gpointer user_data);
private:
GtkBuilder *builder;
GtkWidget *window;
};
LoginWindow::LoginWindow()
{
builder = gtk_builder_new();
gtk_builder_add_from_file (builder, "login_window.glade", NULL);
window = GTK_WIDGET (gtk_builder_get_object (builder, "login_window"));
gtk_builder_connect_signals (builder, NULL);
g_signal_connect(GTK_OBJECT(window), "destroy", GTK_SIGNAL_FUNC(on_window_destroy), NULL);
g_object_unref (G_OBJECT (builder));
gtk_widget_show (window);
}
void LoginWindow::on_window_destroy (GtkObject *object, gpointer user_data)
{
gtk_main_quit();
}
int main (int argc, char *argv[])
{
gtk_init (&argc, &argv);
LoginWindow loginWindow;
gtk_main();
return 0;
}
我這樣做對嗎?我得到編譯錯誤在線:
g_signal_connect(GTK_OBJECT(window), "destroy", GTK_SIGNAL_FUNC(on_window_destroy), NULL);
login_window.cpp: In constructor "LoginWindow::LoginWindow()":
login_window.cpp:27: error: invalid use of member (did you forget the "&" ?)
這樣做的正確方法是什麼?