Skip to main content

Posts

Showing posts from May, 2019

[GTK] Example of using GtkBox with label and button

[1]Source code 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 #include <gtk/gtk.h> void on_window_closed (GtkWidget * window, gpointer data) { gtk_main_quit(); } static void destroy (GtkWidget * widget, gpointer data) { gtk_main_quit(); } static void button_clicked (GtkWidget * button, gpointer data) { g_print( "Button clicked \n " ); } int main ( int argc, char * argv[]) { GtkWidget * window, * label, * box, * button ; gtk_init( & argc, & argv); window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW (window), "Test GTK" ); gtk_window_set_default_size (GTK_WINDOW (window), 500 , 200 ); #if 1 //Use gtk3: change 0->1, Use gtk2: keep it is 0 //Using gtk3 box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5 );

[C++] One way to convert pointer of structure to vector

Of course, you can choose one method of C++ likes reinterpret which is described in below topic: https://www.geeksforgeeks.org/reinterpret_cast-in-c-type-casting-operators/ However, it is easily to find out one big problem in here is: reinterpret_cast is a very special and dangerous type of casting operator In embedded system, this problem is not allowed. Then, we should convert it by manually. The idea is, you push each structure to vector by passing number of structure to function which is used for converting. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 #include <iostream> #include <list> #include <vector> #include <string.h> using namespace std; #define STR_NUM 3 //Number of structures typedef struct { char text_id[ 16 ]; char name[ 16 ]; }st_A; /* Show vector dat