GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Sat Nov 22, 2014 3:02 am

All times are UTC




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: Invalid (NULL) pointer
PostPosted: Thu Aug 14, 2014 1:30 pm 
Offline
Familiar Face

Joined: Sun Aug 10, 2014 1:44 pm
Posts: 6
I got errors like that

Image

In this
http://pastebin.com/jhTAH5Ug
http://pastebin.com/mJbjXYks
http://pastebin.com/UXysYZb8

How to fix that?


Top
 Profile  
 
 Post subject: Re: Invalid (NULL) pointer
PostPosted: Thu Aug 14, 2014 7:14 pm 
Offline
GTK+ Geek

Joined: Sat Jul 26, 2014 11:43 pm
Posts: 60
Try setting up your callback functions as described below. See if that works.

https://developer.gnome.org/gtk3/stable ... arted.html


Top
 Profile  
 
 Post subject: Re: Invalid (NULL) pointer
PostPosted: Thu Aug 14, 2014 8:08 pm 
Offline
Familiar Face

Joined: Sun Aug 10, 2014 1:44 pm
Posts: 6
Which one? There are about four signals in your link.


Top
 Profile  
 
 Post subject: Re: Invalid (NULL) pointer
PostPosted: Thu Aug 14, 2014 9:00 pm 
Offline
GTK+ Geek

Joined: Sat Jul 26, 2014 11:43 pm
Posts: 60
If you go here and scroll down to signals there are a bunch of function prototypes for widget signals.

https://developer.gnome.org/gtk3/stable/GtkWidget.html

You want to match up your parameters in your callback functions with the specific signal.


Top
 Profile  
 
 Post subject: Re: Invalid (NULL) pointer
PostPosted: Fri Aug 15, 2014 5:35 am 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 777
Location: UK
Hello,

Lotherad - You have provided several hundred lines of incomplete code and asked us where the error is without any clue as to where to look.

From looking at the brief error log from the screen shot you gave is it most likely that you are using a signal connect function incorrectly and passing invalid values.

Also from looking at your code it looks like you are a beginner at C++ and GTK+.

Code:
using namespace std;
This is not an error as such, but is considered bad practice. If your application becomes more complex with more name spaces you could end up with a name conflict.

In one of you sections of code you have 32 call-back functions called changedComboBox31() down to changedComboBox(). This is code bloat and can be avoided. If you use signals correctly you can pass you own piece of user data, remembering to cast your functions. This way you can convert your 32 functions into 1 and make your life maintaining the code easier.

GTK+ has bindings for many languages and there are bindings for C++ called gtkmm. If you are going to use C++ you may want to use that instead of the normal C library. This way you can match the language to the binding, but this is optional.

_________________
E.


Top
 Profile  
 
 Post subject: Re: Invalid (NULL) pointer
PostPosted: Fri Aug 15, 2014 2:33 pm 
Offline
Familiar Face

Joined: Sun Aug 10, 2014 1:44 pm
Posts: 6
I know that I can pass some data but I don't know how and Google don't help with passing, for example, an integer.

Quote:
Also from looking at your code it looks like you are a beginner at C++ and GTK+.


Cool that you're the best. I'm gonna leave C++. Thanks.


Top
 Profile  
 
 Post subject: Re: Invalid (NULL) pointer
PostPosted: Fri Aug 15, 2014 8:28 pm 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 777
Location: UK
Google is a good search engine, but it is a general one and its searches will pick up too much other bits which may not be what you need.

I think that I have found your problem. You are trying to connect signals in the function ComboBoxy() using an uninitialised widget.

Below is the corrected code and using data passing to reduce the number of functions needed.
Code:
#include "ComboBoxy.h"
#include "buttony.h"
#include <iostream>

GtkWidget * comboBox[32];

std::string nazwa;

void changedComboBox(GtkComboBox *widget, gpointer user_data)
{
    int i = GPOINTER_TO_SIZE(user_data);

    const char* sciezka = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(comboBox[i]));
    std::string sciezkaString = "media/";
    sciezkaString += sciezka;
    sciezkaString += ".png";

    button[i] = gtk_image_new_from_file(sciezkaString.c_str());
    gtk_button_set_image(GTK_BUTTON(button[i]), buttonImage[i]);
}

void ComboBoxy()
{
    for(int i=0; i<32; i++)
    {
        comboBox[i]=gtk_combo_box_text_new();
        g_object_ref((gpointer) comboBox[i]);
        gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(comboBox[i]), "0", "SC");
        gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(comboBox[i]), "1", "AK47");
        gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(comboBox[i]), "2", "Galil");
        gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(comboBox[i]), "3", "USP");
        gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(comboBox[i]), "4", "Famas");
        gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(comboBox[i]), "5", "UMP45");
        gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(comboBox[i]), "6", "HE");
        gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(comboBox[i]), "7", "FB");
        gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(comboBox[i]), "8", "SG");
        gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(comboBox[i]), "9", "M249");
        gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(comboBox[i]), "10", "M4A1");
        gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(comboBox[i]), "11", "Mac10");
        gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(comboBox[i]), "12", "P90");
        gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(comboBox[i]), "13", "SG552");
        gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(comboBox[i]), "14", "TMP");
        gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(comboBox[i]), "15", "Scout");
        gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(comboBox[i]), "16", "MP5");
        gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(comboBox[i]), "17", "XM1014");
        gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(comboBox[i]), "18", "M3");

        g_signal_connect(comboBox[i], "changed", G_CALLBACK(changedComboBox), GSIZE_TO_POINTER(i);
    }
}

_________________
E.


Top
 Profile  
 
 Post subject: Re: Invalid (NULL) pointer
PostPosted: Fri Aug 15, 2014 11:32 pm 
Offline
Familiar Face

Joined: Sun Aug 10, 2014 1:44 pm
Posts: 6
Thanks for help.


Last edited by Lotherad on Sun Aug 17, 2014 10:48 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Invalid (NULL) pointer
PostPosted: Sat Aug 16, 2014 6:38 am 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 777
Location: UK
Please can you remove the bad language from your last post.

As with everything it takes time to learn and also having someone take a look at things from a different angle can help.

GTK+ and C++ are no exception in having a lot to learn. GTK+ is a very large library which is built upon other libraries that also need to be learnt. These include GLib, GObject, GDK, and Cairo.

C++ is also a complex language in comparison to C and it also has its own library.

By learning these you can achieve great results.

Even now I am still learning new things.

_________________
E.


Top
 Profile  
 
 Post subject: Re: Invalid (NULL) pointer
PostPosted: Sun Aug 17, 2014 10:52 pm 
Offline
Familiar Face

Joined: Sun Aug 10, 2014 1:44 pm
Posts: 6
Aaand it's giving me the same error like when I tried to do it by myself.

Quote:
undefined reference to `changedComboBox()'


Okay, nevermind. I forgot to add

Quote:
extern void changedComboBox(GtkComboBox *widget, gpointer user_data)


To the include file.

Can I ask next question? Is it possible to reset combo box? I mean setting it blank again, like when program starts.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC


Who is online

Users browsing this forum: Yahoo [Bot] and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group