Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to correctly pass QObject on a struct to GstPadProbe through gpointer user_data
QtWS25 Last Chance

How to correctly pass QObject on a struct to GstPadProbe through gpointer user_data

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 185 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sigmind
    wrote on last edited by
    #1

    I want to receive a custom struct of QObject through gpointer on a GstPadProbe callback. I have connected the callback function like this:

    struct customData d;
    
    thread = new QThread();
    
    d.worker = new Worker();
    
    
    d.worker->moveToThread(thread);
    
    d.message = "message\n";
    
    src_pad = gst_element_get_static_pad (osd, "src");
      if (!src_pad)
        g_print ("Unable to get src pad\n");
      else
        gst_pad_add_probe (src_pad, GST_PAD_PROBE_TYPE_BUFFER,
            src_pad_buffer_probe, NULL, NULL);
    
     g_signal_connect(G_OBJECT(src_pad), "src", 
    G_CALLBACK(src_pad_buffer_probe), &d);
    

    My callback function is a probe:

    static GstPadProbeReturn src_pad_buffer_probe (GstPad * pad, GstPadProbeInfo * info, gpointer u_data)
    {
    struct customData *custom = (struct customData *) u_data;
    g_print("Hello World!\n%s\n", custom->message);
    return GST_PAD_PROBE_OK;
    }
    

    I have defined the struct as :

    struct customData{
    char *message;
    Worker *worker;
    
    };
    

    I am trying to access the custom->message on src_pad_buffer_probe() thorough custom struct. But the program crashes unexpectedly. I am experimenting this for GTK and QT multi-threaded communication.

    1 Reply Last reply
    0
    • Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      I would guess 'd' is no longer alive once src_pad_buffer_probe() is called.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      2

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved