I am trying to run a QApplication on button click from Main window.
However I am getting this error:
QCoreApplication::exec: The event loop is already running
My code inside button click is this:
Qt Code:
  1. if (!g_thread_supported ())
  2. g_thread_init (NULL);
  3.  
  4. gst_init (NULL, NULL);
  5. QApplication app(NULL, NULL);
  6. app.connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit ()));
  7.  
  8. // prepare the pipeline
  9.  
  10. GstElement *pipeline = gst_pipeline_new ("xvoverlay");
  11. GstElement *src = gst_element_factory_make ("souphttpsrc",NULL);
  12. GstElement *sink = gst_element_factory_make ("xvimagesink", NULL);
  13. GstElement *jpegdec = gst_element_factory_make("jpegdec",NULL);
  14. //assert(jpegdec);
  15. gst_bin_add_many (GST_BIN (pipeline), src,jpegdec, sink, NULL);
  16. gst_element_link_many(src,jpegdec, sink);
  17.  
  18. g_object_set (src, "location", "http://169.254.75.39/video2.mjpg", NULL);
  19. // prepare the ui
  20.  
  21. QWidget window;
  22. window.setWindowFlags(Qt::Window|Qt::FramelessWindowHint);
  23. window.move(0,400);
  24. window.setFixedSize(320, 200);
  25. window.show();
  26.  
  27. WId xwinid = window.winId();
  28. gst_x_overlay_set_window_handle (GST_X_OVERLAY (sink), xwinid);
  29.  
  30. // run the pipeline
  31.  
  32. GstStateChangeReturn sret = gst_element_set_state (pipeline,
  33. GST_STATE_PLAYING);
  34. if (sret == GST_STATE_CHANGE_FAILURE) {
  35. gst_element_set_state (pipeline, GST_STATE_NULL);
  36. gst_object_unref (pipeline);
  37. // Exit application
  38. QTimer::singleShot(0, QApplication::activeWindow(), SLOT(quit()));
  39. }
  40.  
  41. int ret = app.exec();
  42.  
  43. window.hide();
  44. gst_element_set_state (pipeline, GST_STATE_NULL);
  45. gst_object_unref (pipeline);
To copy to clipboard, switch view to plain text mode 

I am able to run this code,if I put it after
Qt Code:
  1. ui->setupUi(this);
To copy to clipboard, switch view to plain text mode 
in the MainWindow

How can I resolve this problem?