Results 1 to 7 of 7

Thread: Qt without QApplication

  1. #1
    Join Date
    Jul 2008
    Posts
    3
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Qt without QApplication

    How much of Qt can be run without calling QApplication::exec in the main thread? We can call it in another thread, just not the initial one.

    Can we still create windows? Can we draw in them? Does sound still work?

    How much would I break if I never call QApplication::exec?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt without QApplication

    If you never call exec() or processEvents(), events won't be delivered, so using any GUI or network functionality will not be possible. May I ask why you don't want to call QApplication::exec()?

  3. #3
    Join Date
    Jul 2008
    Posts
    3
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt without QApplication

    I'm trying to rewrite an existing graphics library for an introductory C++ class. The library is just a set of function - not event-driven, like Qt. I'd like to keep the API the same, which means I have to drop QApplication::exec, or do something clever (read "stupid") to it.

    The class covers standard C++ on the command line. They write main(){...} and bring up a drawing window by calling a library function, InitGraphics(). Their code is mainly driven by cin/getline and cout/printf, so it has to have a connection to the console.

    The way I see it, unless I can get around QApplication::exec (hence the question), I have to set up another executable (ugh) or figure out another way to run QApplication::exec in another thread from main().

    Mostly I'm curious if anyone has experience with Qt outside of the event loop.

  4. #4
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt without QApplication

    running QApplication does not forbid you to use command line input/output as far as I know.

    if I understand well the what you want to do is rather a kind of interpreter or am I missing something? If you need to keep the CLI, the simplest thing you could do to refactor the I/O would be to use a QTextStream, initialized as follows :
    Qt Code:
    1. QTextStream cli_input(stdin);
    To copy to clipboard, switch view to plain text mode 

    However, you might as well drop the CLI and write a small input window where the user would type some commands and then pass them to your library.

    Hope this helps, even though I'm not sure I fully understood what you want to do.
    Current Qt projects : QCodeEdit, RotiDeCode

  5. #5
    Join Date
    Sep 2007
    Location
    Rome, GA
    Posts
    199
    Thanks
    14
    Thanked 41 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Qt without QApplication

    Not sure if this helps, but we are writing an app for real-time 3D graphics, and we don't call app.exec(), as we need control over the timing of the loop, so we create our own loop and call app.processEvents() and app.sendPostedEvents() when we are ready, then app.exit() when the program shuts down.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt without QApplication

    Actually the correct approach would be to merge both event loops by integrating Qt's abstract event dispatching mechanism. With your current approach you can't have things using local event loops like modal dialogs.

  7. #7
    Join Date
    Mar 2006
    Location
    Mountain View, California
    Posts
    489
    Thanks
    3
    Thanked 74 Times in 54 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt without QApplication

    If all you want is to draw in a window somehow (like logo's turtle graphics), then maybe you can make a simple Qt server application that has a window, and the student's write client applications that issue drawing commands over IPC (qtdbus).

Similar Threads

  1. Must construct QApplication before QPaintDevice
    By sekatsim in forum Qt Programming
    Replies: 16
    Last Post: 8th June 2008, 00:00
  2. QApplication instance
    By nile.one in forum Qt Programming
    Replies: 9
    Last Post: 5th October 2007, 12:06
  3. Calling QApplication from a Non-QT app?
    By hickscorp in forum Qt Programming
    Replies: 2
    Last Post: 10th April 2007, 22:00
  4. Replies: 2
    Last Post: 16th March 2007, 09:04
  5. qapplication with open(/dev/name,O_RDWR) crashed???
    By ttbug in forum Qt for Embedded and Mobile
    Replies: 2
    Last Post: 16th September 2006, 07:56

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
  •  
Qt is a trademark of The Qt Company.