title: g_main_loop_run blocks the Qthread and does not allow to stop video
body: <p>I have created a separate class for gstreamer to stream videos.<br>
  This class runs on separate thread by using moveToThread().<br>
  I am using Qt5.5 for development.<br>
  When I issue startcommand on main thread , Qthread starts and gstreamer uses <code>g_main_loop_run</code> to stream videos. This works absolutely fine. But somehow <code>g_main_loop_run</code> blocks the thread and when I issue signal to stop video from main thread , it doesnt execute slot in gstreamer class.    </p>
  
  <p>Can someone please advice me how to resolve that issue? Either I can replace <code>g_main_loop_r</code>un with someother command or may be use <code>g_main_loop_quit( gloop )</code>; in another way.</p>
  
  <pre><code>void StreamingVideo::slotStartStream() // this slot called on start of thread from main thread
  {
  
      if( !isElementsLinked() )
      {
         qDebug() &lt;&lt; " we are emitting in dummy server ";
          //emit sigFailed( "elementsFailed" ); // WILL CONNECT IT WITH MAIN GUI ONXCE CODE IS FINISHED
          return;
      }
  
      gst_bus_add_watch( bus, busCall, gloop );
      gst_object_unref( bus );
  
      //proper adding to pipe
      gst_bin_add_many( GST_BIN( pipeline ), source, capsFilter, conv, videoRate, capsFilterRate,
                        clockDisplay, videoEnc, udpSink, NULL
                       );
  
      //proper linking:
      gst_element_link_many( source, capsFilter, conv, videoRate, capsFilterRate, clockDisplay, videoEnc, udpSink, NULL );
  
      g_print("Linked all the Elements together\n");
      gst_element_set_state( pipeline, GST_STATE_PLAYING );
      // Iterate
      g_print ("Running...\n");
      emit sigStartStream(); // signal to main thread to issue success command . works fine
      g_main_loop_run( gloop );
      g_print ("Returned, stopping playback\n");
      //gst_element_set_state (pipeline, GST_STATE_NULL);
      if( g_main_loop_is_running( gloop ) )
      {
          qDebug() &lt;&lt; " in g_main_loop_is_runnung  emiting signal ";
          emit sigStartStream();
      }
      if( !g_main_loop_is_running( gloop) )
      {
          qDebug() &lt;&lt; "in not gmain running thread id";
          qDebug() &lt;&lt; QThread::currentThreadId();
      }
  
  }
  
  
  
  void StreamingVideo::slotStopStream() // THIS SLOT IS NOT CALLED WHEN VIDEO RUNNING
  {
      qDebug() &lt;&lt; " we are planning to stop streaming  stramingVideo::slotStopStream ";
      g_print ("Returned, stopping playback\n");
      g_main_loop_quit( gloop );
      gst_element_set_state (pipeline, GST_STATE_NULL);
     // g_main_loop_quit( gloop );
      releaseMemory();
      emit sigStopStream(); // signal to main thread to issue message saying video has stopped.
  }
  </code></pre>
  
  <p>// somewhere in main thread</p>
  
  <pre><code> threadStreaming = new QThread();
   streamVideo    = new StreamingVideo( "127.0.0.1"); // we will automate this ip address later on
  
          streamVideo-&gt;moveToThread( threadStreaming );
  
          connect( threadStreaming, SIGNAL( started() ),        streamVideo,     SLOT( slotStartStream() ) );
          connect( streamVideo,     SIGNAL( sigStopStream() ),  threadStreaming, SLOT( quit() ) );
          connect( streamVideo,     SIGNAL( sigStopStream() ),  streamVideo,     SLOT(deleteLater() ) );
          connect( threadStreaming, SIGNAL( finished() ),       threadStreaming, SLOT(deleteLater() ) );
  
          connect( streamVideo,     SIGNAL( sigStartStream() ), this, SLOT( slotTrueStreamRun()  ) );
          connect( streamVideo,     SIGNAL( sigStopStream() ),  this, SLOT( slotFalseStreamRun() ) );
  
          connect( this,            SIGNAL( sigMopsCamStopCmd() ), streamVideo, SLOT(slotStopStream() ) );
          threadStreaming-&gt;start();
  </code></pre>