Skip to content

Commit 4673cbe

Browse files
committed
added hello world in gtkmm (C++)
1 parent 5aee5f4 commit 4673cbe

File tree

5 files changed

+54
-0
lines changed

5 files changed

+54
-0
lines changed

hello/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hello

hello/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
g++ main.cpp hello.cpp -o hello `pkg-config --cflags --libs gtkmm-4.0` -std=c++20

hello/hello.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include "hello.hpp"
2+
3+
#include <iostream>
4+
5+
Hello::Hello() : button_("Hello World") {
6+
button_.set_margin(10);
7+
8+
button_.signal_clicked().connect(sigc::mem_fun(*this,
9+
&Hello::on_button_clicked));
10+
11+
// This packs the button into the Window (a container).
12+
set_child(button_);
13+
}
14+
15+
Hello::~Hello() {
16+
}
17+
18+
void Hello::on_button_clicked()
19+
{
20+
std::cout << "Hello World" << std::endl;
21+
}
22+

hello/hello.hpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#ifndef HELLO_HPP
2+
#define HELLO_HPP
3+
4+
#include <gtkmm/button.h>
5+
#include <gtkmm/window.h>
6+
7+
class Hello : public Gtk::Window {
8+
public:
9+
Hello();
10+
~Hello() override;
11+
12+
protected:
13+
//Signal handlers:
14+
void on_button_clicked();
15+
16+
//Member widgets:
17+
Gtk::Button button_;
18+
};
19+
20+
#endif // HELLO_HPP

hello/main.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include "hello.hpp"
2+
3+
#include <gtkmm/application.h>
4+
5+
int main(int argc, char* argv[]) {
6+
auto app = Gtk::Application::create("org.gtkmm.example");
7+
8+
//Shows the window and returns when it is closed.
9+
return app->make_window_and_run<Hello>(argc, argv);
10+
}

0 commit comments

Comments
 (0)