why isn't GdkEventKey declared anywhere?

80 Views Asked by At

I am studying keyboard events from the docs and came across this method

Updated

Here is the simplified version of the code in a signle file with the same error but now it show extra errors

/home/test/Desktop/not_working/main.cpp:15:52: error: ‘GdkEventKey’ has not been declared
   15 |                 bool on_key_press_or_release_event(GdkEventKey * event){
      |                                                    ^~~~~~~~~~~
/home/test/Desktop/not_working/main.cpp: In constructor ‘App::App()’:
/home/test/Desktop/not_working/main.cpp:13:13: error: ‘class Gtk::Box’ has no member named ‘signal_key_press_event’
   13 |         box.signal_key_press_event().connect(sigc::mem_fun(*this, &App::on_key_press_or_release_event));
      |             ^~~~~~~~~~~~~~~~~~~~~~
/home/test/Desktop/not_working/main.cpp: In member function ‘bool App::on_key_press_or_release_event(int*)’:
/home/test/Desktop/not_working/main.cpp:16:38: error: request for member ‘type’ in ‘* event’, which is of non-class type ‘int’
   16 |                           if (event->type == GDK_KEY_PRESS && event->keyval == GDK_KEY_Return)
      |                                      ^~~~
/home/test/Desktop/not_working/main.cpp:16:70: error: request for member ‘keyval’ in ‘* event’, which is of non-class type ‘int’
   16 |                           if (event->type == GDK_KEY_PRESS && event->keyval == GDK_KEY_Return)
      |     

main.cpp

#include <gtkmm.h>
#include <stdio.h>

class App: public Gtk::Window{
    protected:
        Gtk::Box box;
        Gtk::Text text;
    public:
        App(){
                set_child(box);
                box.append(text);
                text.set_text("hello world");
                //box.signal_key_press_event().connect( sigc::ptr_fun(&on_key_press_or_release_event) );
        }
        bool on_key_press_or_release_event(GdkEventKey * event){
              if (event->type == GDK_KEY_PRESS && event->keyval == GDK_KEY_Return)
              {
                printf("Hello there"); 
                return true;
              }
              return false;
        }
};

int main(int argc, char * argv[])
{
    auto app = Gtk::Application::create("org.example.github.basic");
    app->make_window_and_run<App>(argc, argv);
    return 0;
}

and I am using cmake/make to compile it

cmake_minimum_required(VERSION 3.0)
project(example)
find_package(PkgConfig)
pkg_check_modules(GTKMM REQUIRED gtkmm-4.0)
add_executable(app main.cpp)
target_include_directories(app PRIVATE ${GTKMM_INCLUDE_DIRS})
target_compile_options(app PRIVATE ${GTKMM_CFLAGS_OTHER})
target_link_libraries(app PRIVATE ${GTKMM_LIBRARIES})

why does this code state that the GdkEventKey isn't declared anywhere?

0

There are 0 best solutions below