void, chcem sa ta spytat ci je tento kod dobry pre c++. Dik
Tak som nieco poriesil s tymi GTK tak to tu pisem. Ak mate teda Debian, Eclipse, C++.
Najprv si cez terminal nainstalujte ako root: apt-get install libgtk-3-dev gdb eclipse-cdt build-essential cmake git pkg-config. ja som si nainstaloval aj gtk-3.0. Instalujte to po jednom.
eclipse-cdt uz asi mate, ak nie, je tu teraz asi najnovsia verzia 2020/9:
https://www.eclipse.org/downloads/packages/installer napravo - "download x86_64" teda ak mate 64-bit.
teraz chodte do eclipsu do menu Help / Eclipse Marketplace
ked ste v Marketplace do vyhladavaca zadajte: pkg_config - ked vam ho naslo dajte "install"
(mne to v predoslej verzii 2020/6 nechcelo najst... az ked som nainstaloval tuto novsiu 2020/9 tak to slo, ale ja si myslim, ze to mohlo byt tym, ze predtym som si nainstaloval tu na marketplace Darkest Dark Theme. maju pekne farby a velky vyber, ale myslim, ze odvtedy nebol eclipse uplne v poriadku.)
ak je to potrebne restartujte eclipse
teraz chodte znovu do eclipse a zalozte si novy project: File / New / C/C++ Project, potom okno "C++ Managed build" dalej "Next" hore zadajte meno projektu, vyberte "Empty Project"
"Linux GCC" stlacte "Finish".
Potom nalavo v "Project Explorer" vidite vas project. Kliknite nan pravym tlacidlom a vyberte: "New" -> "Source File"
teraz chodte do menu Project / Properties / C/C++ Build - rozbalte a tam je "Settings". Ste na karte "Tool Settings" tak na tu kartu kliknite mysou a posuvajte sa sipkami do prava az pridete na kartu pkg-config, ktora je posledna a nie je ju hned vidiet.
Ked ste uz na karte pkg-config tak chodte dole a zaskrtnite "gtk+-3.0" to by malo byt vsetko co sa tyka nastaveni. dajte restart ak je treba.
teraz chodte do svojho noveho projectu a do source file a skopirujte tento kod.
Kód:
#include <iostream>
#include <gtk-3.0/gtk/gtk.h>
using namespace std;
// callback function which is called when button is clicked
void on_button_clicked(GtkButton *btn, gpointer data)
{
// change button label when it's clicked
gtk_button_set_label(btn, "Hello World");
}
// callback function which is called when application is first started
void on_app_activate(GApplication *app, gpointer data)
{
// create a new application window for the application
// GtkApplication is sub-class of GApplication
// downcast GApplication* to GtkApplication* with GTK_APPLICATION() macro
GtkWidget *window = gtk_application_window_new(GTK_APPLICATION(app));
// a simple push button
GtkWidget *btn = gtk_button_new_with_label("Click Me!");
// connect the event-handler for "clicked" signal of button
g_signal_connect(btn, "clicked", G_CALLBACK(on_button_clicked), NULL);
// add the button to the window
gtk_container_add(GTK_CONTAINER(window), btn);
// display the window
gtk_widget_show_all(GTK_WIDGET(window));
}
int main(int argc, char *argv[])
{
// create new GtkApplication with an unique application ID
GtkApplication *app = gtk_application_new
(
"org.gtkmm.example.HelloApp",
G_APPLICATION_FLAGS_NONE
);
// connect the event-handler for "activate" signal of GApplication
// G_CALLBACK() macro is used to cast the callback function pointer
// to generic void pointer
g_signal_connect(app, "activate", G_CALLBACK(on_app_activate), NULL);
// start the application, terminate by closing the window
// GtkApplication* is upcast to GApplication* with G_APPLICATION() macro
int status = g_application_run(G_APPLICATION(app), argc, argv);
// deallocate the application object
g_object_unref(app);
return status;
}