Thread: warning: assignment from incompatible pointer type - drawing_area

  1. #1
    Registered User
    Join Date
    Dec 2016
    Posts
    30

    warning: assignment from incompatible pointer type - drawing_area

    Hi folks,

    In function main() I do the following declaration:

    Code:
      
    GtkWidget *drawing_area;
    
    drawing_area = gtk_builder_get_object (builder, "draw_area");
    where builder was created from a .ui file and "draw_area" is the ID of my drawing area in the .ui file.

    When I compile the code, even though the program appears to run successfully, the gcc compiler shouts at me:

    warning: assignment from incompatible pointer type [-Wincompatible-pointer-types]
    drawing_area = gtk_builder_get_object (builder, "draw_area");
    ^
    Why is this happening? I have other GObjects declared in a similar way and the compiler doesn't complain about them.

  2. #2
    Registered User
    Join Date
    Jun 2015
    Posts
    1,643
    The compiler doesn't know that GtkWidget* and GObject* are compatible (i.e., it doesn't know that GtkWidget "is-a" GObject). You need to either make drawing_area a GObject* or cast the return value of gtk_builder_get_object to a GtkWidget*.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. warning: assignment from incompatible pointer type.
    By ingeniousreader in forum C Programming
    Replies: 4
    Last Post: 03-06-2012, 09:00 AM
  2. How would I fix this incompatible pointer type warning
    By ogglock in forum C Programming
    Replies: 2
    Last Post: 07-11-2011, 01:17 AM
  3. [Warning] Incompatible pointer type
    By dgs012 in forum C Programming
    Replies: 5
    Last Post: 02-20-2011, 11:27 AM
  4. Incompatible Pointer Type Warning
    By kwikness in forum C Programming
    Replies: 5
    Last Post: 10-30-2007, 06:14 PM
  5. warning: assignment from a incompatible pointer type
    By enderandrew in forum C Programming
    Replies: 8
    Last Post: 09-22-2007, 04:07 AM

Tags for this Thread