Results 1 to 4 of 4

Thread: Does Qt widgets work without it's main Event loop?

  1. #1
    Join Date
    Apr 2010
    Location
    Bahamas
    Posts
    29
    Thanks
    3
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Does Qt widgets work without it's main Event loop?

    Hi,

    Does anybody have any idea if Qt widgets still work without enabling Qt's main Event loop? Like for example, I will have a custom main Event loop and Qt is only used for drawing only? And if possible, my main Event loop's events are passed to Qt widgets, like key press events.

    Or does Qt only works as a stand-alone application, and it can't be used only for screen drawing purposes alone.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Does Qt widgets work without it's main Event loop?

    it depends what you mean with "work".

    But, the question is, why do you want to use a custom event loop instead of adding your events the Qt event loop.
    Its my guess, that if you review your needs and goals, a custom event loop will not be the correct way to go, but I can't say, since you didn't explain the reasoning behind your question.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Apr 2010
    Location
    Bahamas
    Posts
    29
    Thanks
    3
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Does Qt widgets work without it's main Event loop?

    high_flyer,

    Sorry for not being clear. Thanks for your initial answer. What I mean by "work" is that will the widgets still at least draw on the screen even if Qt's main event loop is disabled?

    My reason for doing this is that I have this existing c++ program that can already act as an event loop. It receives system-wide and application-wide events and manages them. I would like to have a GUI for this c++ program and I chose Qt framework to build this. So I was planning to reuse this c++ program's event loop and just use Qt for drawing purposes only.

    I've an experience in creating customized GUI frameworks and I'm not confident in doing the above method(disabling the event loop of Qt). Because in my experience, at least the drawing of the widgets are sometimes driven by timers.

    If I'm not wrong, if I will not use Qt's main event loop, then its like reinventing it. Again my question is, will the widgets still work even if its main event loop is disabled? I've tried creating a simple hello world program and creating a simple QDialog with an endless loop that acts as the main loop of the main thread. Unfortunately, Qt requires a QApplication to be created and its "exec" function to be called.

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Does Qt widgets work without it's main Event loop?

    Unfortunately, Qt requires a QApplication to be created and its "exec" function to be called
    That is true, and AFAIK you can't avoid it if you are creating a Qt project.
    The "correct" way to do what you want is to subclass QApplication and re-implement its event loop.
    Not something I would recommend.

    Does your application have a GUI, or is it a console application?
    If its a console application you can use your console application in your Qt GUI as a QProcess, or might go for a server-client configuration, where the Qt app or .DLL/.so only do the GUI front end, as one idea.
    If you are under Linux DBus might also be an idea.
    Last edited by high_flyer; 10th June 2010 at 09:51.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. Replies: 10
    Last Post: 15th January 2010, 15:35
  2. How to log returning control back to the main event loop?
    By piotr.dobrogost in forum Qt Programming
    Replies: 5
    Last Post: 28th September 2009, 10:57
  3. Main Thread Event loop
    By ^NyAw^ in forum Qt Programming
    Replies: 1
    Last Post: 20th March 2007, 13:10
  4. How to bind Qt3 and Qt4 main event loop.
    By Opilki_Inside in forum Qt Programming
    Replies: 7
    Last Post: 10th May 2006, 09:04
  5. Workload in a QThread blocks main application's event loop ?
    By 0xBulbizarre in forum Qt Programming
    Replies: 14
    Last Post: 9th April 2006, 22:55

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.