|
|||||||||
| Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
linux operating commands and unix operating commands |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
||||
|
||||
|
I am using this code: Code:
g_signal_connect(showapp_option, "activate", G_CALLBACK(&MainWindow::show_app), appindicator); so as to connect my indicator menu item to the function show_app(), and it works just fine, irregardless the fact that I get the following warning: Code:
warning: converting from 'void (MainWindow::*)()' to 'GCallback {aka void (*)()}' [-Wpmf-conversions]I don't understand the warning as I've never worked with the gtk libs before... Anyway, this isn't the real reason I'm posting here, but it is maybe related to it. The problem is that I cannot use 'this' (which stands for the MainWindow's call) from inside show_app() function, because the program crashes! Why I cannot use 'this' inside the function? And, more importantly, how do I make it work?
|
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
We need to see more context.
|
| Sponsored Links | ||
|
|
|
#3
|
||||
|
||||
|
Ok, here it is: Code:
void MainWindow::show_app(){
//crash here:
this->show();
//this works fine:
app_indicator_set_status(appindicator, APP_INDICATOR_STATUS_PASSIVE);
}
void MainWindow::make_indicator()
{
if(appindicator){
//appindicator has already been created
return;
}
appindicator = app_indicator_new("Format Junkie Indicator", "formatjunkie", APP_INDICATOR_CATEGORY_APPLICATION_STATUS);
GtkWidget* showapp_option;
GtkWidget* add_audio_option;
//GtkWidget* subitem3;
GtkWidget* indicatormenu = gtk_menu_new();
GtkWidget* item = gtk_menu_item_new_with_label("Format Junkie main menu");
gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), indicatormenu);
showapp_option = gtk_menu_item_new_with_label("Show App!");
g_signal_connect(showapp_option, "activate", G_CALLBACK(&MainWindow::show_app), appindicator);
gtk_menu_shell_append(GTK_MENU_SHELL(indicatormenu), showapp_option);
add_audio_option = gtk_menu_item_new_with_label("Add audio files");
g_signal_connect(add_audio_option, "activate", G_CALLBACK(&MainWindow::add_audio_files), appindicator);
gtk_menu_shell_append(GTK_MENU_SHELL(indicatormenu), add_audio_option);
/*
subitem3 = gtk_menu_item_new_with_label("Quit");
g_signal_connect(subitem3, "activate", G_CALLBACK(quit_from_indicator), appindicator);
gtk_menu_shell_append(GTK_MENU_SHELL(menu), subitem3);*/
gtk_widget_show_all(indicatormenu);
app_indicator_set_status(appindicator, APP_INDICATOR_STATUS_ACTIVE);
app_indicator_set_attention_icon(appindicator, "dialog-warning");
app_indicator_set_menu(appindicator, GTK_MENU (indicatormenu));
} |
| The Following User Says Thank You to hakermania For This Useful Post: | ||
Corona688 (06-28-2012) | ||
|
#4
|
||||
|
||||
|
You are forcing a conversion from a class member to a function call. Class members have this, function calls don't. So it crashes. If you make the member function static, you'll be able to call it, since static member functions don't have 'this'. So you won't have this but you can make do -- that's what the data parameter in a GTK callback is for instead. You can pass a long a pointer for data you need later. Pass in the class itself and you can go datapointer->whatever. Code:
// You'll have to change the definition in the header file too, if any
static void MainWindow::show_app(MainWindow *data){
data->show();
//crash here:
// this->show();
//this works fine:
app_indicator_set_status(appindicator, APP_INDICATOR_STATUS_PASSIVE);
}
void MainWindow::make_indicator()
{
if(appindicator){
//appindicator has already been created
return;
}
appindicator = app_indicator_new("Format Junkie Indicator", "formatjunkie", APP_INDICATOR_CATEGORY_APPLICATION_STATUS);
GtkWidget* showapp_option;
GtkWidget* add_audio_option;
//GtkWidget* subitem3;
GtkWidget* indicatormenu = gtk_menu_new();
GtkWidget* item = gtk_menu_item_new_with_label("Format Junkie main menu");
gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), indicatormenu);
showapp_option = gtk_menu_item_new_with_label("Show App!");
g_signal_connect(showapp_option, "activate", G_CALLBACK(&MainWindow::show_app), this);
gtk_menu_shell_append(GTK_MENU_SHELL(indicatormenu), showapp_option);
add_audio_option = gtk_menu_item_new_with_label("Add audio files");
g_signal_connect(add_audio_option, "activate", G_CALLBACK(&MainWindow::add_audio_files), this);
gtk_menu_shell_append(GTK_MENU_SHELL(indicatormenu), add_audio_option);
/*
subitem3 = gtk_menu_item_new_with_label("Quit");
g_signal_connect(subitem3, "activate", G_CALLBACK(quit_from_indicator), appindicator);
gtk_menu_shell_append(GTK_MENU_SHELL(menu), subitem3);*/
gtk_widget_show_all(indicatormenu);
app_indicator_set_status(appindicator, APP_INDICATOR_STATUS_ACTIVE);
app_indicator_set_attention_icon(appindicator, "dialog-warning");
app_indicator_set_menu(appindicator, GTK_MENU (indicatormenu));
}You'll have to do the same with add_audio_files, too. Last edited by Corona688; 06-28-2012 at 04:16 PM.. |
| The Following User Says Thank You to Corona688 For This Useful Post: | ||
hakermania (06-28-2012) | ||
| Sponsored Links | |
|
|
#5
|
||||
|
||||
|
Thanks for this! Still, it doesn't work! This is my code: Code:
void MainWindow::show_app(MainWindow *data){
data->show();
app_indicator_set_status(appindicator, APP_INDICATOR_STATUS_PASSIVE);
}
void MainWindow::make_indicator()
{
if(appindicator){
//appindicator has already been created
return;
}
appindicator = app_indicator_new("Format Junkie Indicator", "formatjunkie", APP_INDICATOR_CATEGORY_APPLICATION_STATUS);
GtkWidget* showapp_option;
GtkWidget* add_audio_option;
//GtkWidget* subitem3;
GtkWidget* indicatormenu = gtk_menu_new();
GtkWidget* item = gtk_menu_item_new_with_label("Format Junkie main menu");
gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), indicatormenu);
showapp_option = gtk_menu_item_new_with_label("Show App!");
g_signal_connect(showapp_option, "activate", G_CALLBACK(&MainWindow::show_app), this);
gtk_menu_shell_append(GTK_MENU_SHELL(indicatormenu), showapp_option);
add_audio_option = gtk_menu_item_new_with_label("Add audio files");
g_signal_connect(add_audio_option, "activate", G_CALLBACK(&MainWindow::add_audio_files), this);
gtk_menu_shell_append(GTK_MENU_SHELL(indicatormenu), add_audio_option);
gtk_widget_show_all(indicatormenu);
app_indicator_set_status(appindicator, APP_INDICATOR_STATUS_ACTIVE);
app_indicator_set_attention_icon(appindicator, "dialog-warning");
app_indicator_set_menu(appindicator, GTK_MENU (indicatormenu));
}In the header file: Code:
private slots:
static void show_app(MainWindow *data);It doesn't let me add 'static' in front of the function in the .cpp file, because of Code:
error: cannot declare member function 'static void MainWindow::show_app(MainWindow*)' to have static linkage [-fpermissive] Also, the warning didn't go. Thanks! |
| Sponsored Links | |
|
|
#6
|
||||
|
||||
|
The warning is a warning. If you know why it's there and what you're doing, you can ignore it. It's saying -fpermissive might allow you to follow that suggestion but it might not be a good idea. I think that used to be perfectly valid, but standards are changing, so let's follow its suggestion and do that another way. Let's make global functions instead of static ones... Code:
// Completely outside the class
void show_app_stub(MainWindow *data)
{
data->show_app();
}
...
// in make_indicator
g_signal_connect(showapp_option, "activate", G_CALLBACK(show_app_stub), this); |
| The Following User Says Thank You to Corona688 For This Useful Post: | ||
hakermania (06-28-2012) | ||
| Sponsored Links | |
|
|
#7
|
||||
|
||||
|
Thanks again. The warning's gone but the crush is still there...
|
| Sponsored Links | ||
|
|
![]() |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| combining awk and sed | senthil.ak | Shell Programming and Scripting | 8 | 02-21-2011 09:29 AM |
| Problem combining two variables into one | Eraser | Shell Programming and Scripting | 3 | 12-17-2009 08:01 AM |
| 'Combining 2 while loops together' | Firestarter | Shell Programming and Scripting | 2 | 01-30-2009 06:10 AM |
| combining fields in awk | json4639 | Shell Programming and Scripting | 2 | 07-10-2008 03:52 PM |
| Combining 2 scripts | achararun | Shell Programming and Scripting | 4 | 12-11-2006 09:05 AM |
|
|