Visit The New, Modern Unix Linux Community


Combining Qt with GTK only one problem!


 
Thread Tools Search this Thread
Top Forums Programming Combining Qt with GTK only one problem!
# 1  
Question Combining Qt with GTK only one problem!

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?Smilie
# 2  
We need to see more context.
# 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));
}

This User Gave Thanks to hakermania For This Post:
# 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..
This User Gave Thanks to Corona688 For This Post:
# 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!
# 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);

This User Gave Thanks to Corona688 For This Post:
# 7  
Thanks again. The warning's gone but the crush is still there...

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #314
Difficulty: Easy
Pointers were not used in the original C programming language and were added later in in C++.
True or False?

9 More Discussions You Might Find Interesting

1. Fedora

GTK Themes

Hi, So, I have a GTK based GUI app. I used GTKdevel-2.24 to develop and compile it on two different distros of linux: Fedora 14 and Linaro (tablet). All of my code was the same for each but compiled on each platform separately (32bit and ARM). Both distros run the application. On Fedora 14... (0 Replies)
Discussion started by: fedora18
0 Replies

2. Shell Programming and Scripting

awk problem - combining awk statements

i have a datafile that has several lines that look like this: 2,dataflow,Sun Mar 17 16:50:01 2013,1363539001,2990,excelsheet,660,mortar,660,4 using the following command: awk -F, '{$3=strftime("%a %b %d %T %Y,%s",$3)}1' OFS=, $DATAFILE | egrep -v "\-OLDISSUES," | ${AWK} "/${MONTH} ${DAY}... (7 Replies)
Discussion started by: SkySmart
7 Replies

3. UNIX for Dummies Questions & Answers

Gtk-WARNING **:

Hi all, I want to run a 32 bit program on a 64 bit linux machine. Installing the program was no issue but when I try to run it I get Warnings that look like this: Gtk-WARNING **: Unable to locate theme engine in module_path: "oxygen-gtk" Gtk-WARNING **: Unable to locate theme engine in... (3 Replies)
Discussion started by: friend
3 Replies

4. Programming

curses.h not found , gtk/gtk.h not found

i have downloaded <libncurses5-dev_5.7+20101128-1_i386.deb> and <ndk++-0.0.1alpha4.tar.bz2> which contains the header files curses.h and gtk/gtk.h .. i have also included them using .. #include "/home/ball/Desktop/Sudoku/project/libncurses5-dev_5.7+20101128-1_i386/usr/include/curses.h" ... (2 Replies)
Discussion started by: upvan111
2 Replies

5. Shell Programming and Scripting

Problem combining two variables into one

Hello, I have a problem combining two variables into one. I did the following: in my env variables i had set PATH_DESTINATION_1=/root/path_one PATH_DESTINATION_2=/root/path_two #!/usr/bin/ksh count=1 count_path=2 while do (3 Replies)
Discussion started by: Eraser
3 Replies

6. Programming

GUI without GTK - Is it possible?

Is GUI programming without GTK possible? If so, how? Or what libraries should I #include? Google seems to tell me that GUI programming in C++ is much more popular then in C. I'm assuming because of the Object Orientedness (if that is even a word)? Before you say things like "Search the forums",... (5 Replies)
Discussion started by: Octal
5 Replies

7. Post Here to Contact Site Administrators and Moderators

GTK+ project

Hai, I am santhosh,I am fresher to this Forum,I want details about GTK+ Project(All Widgets--- I mean how they are programming in callback.c file). if it possible please send information regarding this Glade tool.I want to interface glade with Modbus protocol, Thankyou with best regards,... (0 Replies)
Discussion started by: santhosh.linux
0 Replies

8. Linux

GTK+ hates me

I am very new to the linux environment. I have been interested in it for years but have just recently had the courage to pop that install disk into my PC. Because of it's ease of installation, I installed Mandrake 9.1 and I'm running KDE3.1 for my GUI. Right now I'm trying to conquer the world... (5 Replies)
Discussion started by: n0data
5 Replies

9. UNIX for Dummies Questions & Answers

how to start my gtk+

hi, i am a total dummy of unix. i am not used to the unix convention and practice. currently i am trying to install and use the solaris GUI based ftp program called gtk+ (gtk+-1.2.10-sol8-sparc-local.gz). i downloaded it and installed it successfully on my Sun Solaris sparc version 8. ... (4 Replies)
Discussion started by: champion
4 Replies

Featured Tech Videos