Results 1 to 14 of 14

Thread: event loop already running

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2013
    Location
    Bangalore,India
    Posts
    64
    Thanks
    21
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default event loop already running

    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?

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: event loop already running

    From QApplication doc : For any GUI application using Qt, there is precisely one QApplication object, no matter whether the application has 0, 1, 2 or more windows at any given time. You can not have multiple QApplication objects.

  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: event loop already running

    How does your main() function look like? Do you create and run a QApplication in there already?

    Cheers,
    _

  4. #4
    Join Date
    Oct 2013
    Location
    Bangalore,India
    Posts
    64
    Thanks
    21
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: event loop already running

    My main() function is like this:
    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QApplication a(argc, argv);
    4. MainWindow w;
    5. w.show();
    6. return a.exec();
    7. }
    To copy to clipboard, switch view to plain text mode 

    I have created 1 QApplication object there also

  5. #5
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: event loop already running

    Then this is enough.
    Just remove the QApplication stuff from your slot.

    Cheers,
    _

  6. #6
    Join Date
    Oct 2013
    Location
    Bangalore,India
    Posts
    64
    Thanks
    21
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: event loop already running

    I have removed the QApplication stuff from my code.
    But now nothing is being shown.No error also.
    Here is the modified code:
    Qt Code:
    1. if (!g_thread_supported ())
    2. g_thread_init (NULL);
    3.  
    4. gst_init (NULL, NULL);
    5. //QApplication app(NULL, NULL);
    6. //a.connect(&a, SIGNAL(lastWindowClosed()), &a, 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. gst_bin_add_many (GST_BIN (pipeline), src,jpegdec, sink, NULL);
    15. gst_element_link_many(src,jpegdec, sink);
    16. g_object_set (src, "location", "http://169.254.75.39/video2.mjpg", NULL);
    17. // prepare the ui
    18.  
    19. QWidget window;
    20. window.setWindowFlags(Qt::Window|Qt::FramelessWindowHint);
    21. window.move(1000,480);
    22. window.setFixedSize(320, 200);
    23. window.show();
    24.  
    25. WId xwinid = window.winId();
    26. gst_x_overlay_set_window_handle (GST_X_OVERLAY (sink), xwinid);
    27.  
    28. // run the pipeline
    29.  
    30. GstStateChangeReturn sret = gst_element_set_state (pipeline,
    31. GST_STATE_PLAYING);
    32. if (sret == GST_STATE_CHANGE_FAILURE) {
    33. gst_element_set_state (pipeline, GST_STATE_NULL);
    34. gst_object_unref (pipeline);
    35. // Exit application
    36. //QTimer::singleShot(0, QApplication::activeWindow(), SLOT(quit()));
    37. }
    38.  
    39. //int ret = a.exec();
    40.  
    41. window.hide();
    42. gst_element_set_state (pipeline, GST_STATE_NULL);
    43. gst_object_unref (pipeline);
    To copy to clipboard, switch view to plain text mode 

  7. #7
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: event loop already running

    Quote Originally Posted by prkhr4u View Post
    I have removed the QApplication stuff from my code.
    But now nothing is being shown.No error also.
    Because in line 41 You hide new window.

  8. #8
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: event loop already running

    Because in line 41 You hide new window.
    Worse than that. The window is created on the stack in line 19, so as soon as control exits the if() clause starting on line 1, the window goes out of scope and is destroyed. Poof! Now you see it, now you don't!

  9. The following user says thank you to d_stranz for this useful post:

    prkhr4u (12th February 2014)

Similar Threads

  1. Not able to receive the custom event from the event loop
    By Jagadeeshakr in forum Qt Programming
    Replies: 1
    Last Post: 20th July 2012, 11:47
  2. Qt/MFC Event Loop - stop MFC receiving event?
    By Kaylx in forum Qt Programming
    Replies: 1
    Last Post: 26th April 2012, 18:57
  3. Replies: 4
    Last Post: 6th August 2011, 01:40
  4. Replies: 10
    Last Post: 15th January 2010, 14:35
  5. Replies: 0
    Last Post: 23rd October 2008, 12:43

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.