Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 422255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T19:03:48+00:00 2026-05-12T19:03:48+00:00

I am writing an application in C++ with using GTK+ (not gtkmm) so I

  • 0

I am writing an application in C++ with using GTK+ (not gtkmm) so I need to compile using g++ compiler. Is it possible to compile GTK+ applications with the g++ compiler? Are GTK+ and libraries compatible with g++ compiler?

I am trying to embed GTK+ functions call in a class like follows:

#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;
}

Am I doing it right? I am getting compile error on line:

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 "&" ?)

What is the right way of doing it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T19:03:49+00:00Added an answer on May 12, 2026 at 7:03 pm

    Gtk+ is a C-based library, so you can’t give it class-member-functions as callbacks. Either define C-style functions as callbacks i.e.

    extern "C"
    void on_window_destroy( GtkObject *object, gpointer user_data)
    {
      // do yer stuff.. keep in mind, there's no this-pointer here, it's not
      // associated with an object
    }
    

    outside of any class declarations. When registering the signal, you might want to add the LoginWindow-object itself as user_data and simply cast it when entering the method and
    forward the call, like so

    extern "C"
    void on_window_destroy( GtkObject *object, gpointer user_data)
    {
      static_cast<LoginWindow*>(user_data)->on_window_destroy();
    }
    

    If you want to do it c++ style though, have a look at gtkmm, which is the c++ wrapper for Gtk+, and it’ll give you a lot more OOP for your buck. It’s a little more messy to work with signals/callbacks in gtkmm, but it’s type safe and will save you a lot of headaches in the end.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing an application using the crypto++ library. For those not familiar with
I'm writing an application using WPF, and I need to make something that looks
I am writing a silverlight application using c#. For the project I need to
I am writing an application using the OpenCV libraries, the Boost libraries and a
I am writing a C++ application using GTK and OpenGL. I have a GTK
I am writing an application using openFrameworks, but my question is not specific to
I am writing application using PhoneGap on Android. I need to call some PhoneGap
I'm writing an application using WPF, and I need to make something that looks
I am writing a simple application and am using glade (gtk) for the UI.
I am writing an application using labview and need to use external code. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.