Results 1 to 4 of 4

Thread: QT dialogs in a console application

  1. #1

    Default QT dialogs in a console application

    Hello,

    I have developed a custom QGLWidget for rendering 3D content. Besides in the regular gui-application, I want to use it in a console app. This program basically performs a list of tasks and I'd sometimes like to use the QGLWidget for debugging purposes. However, the console application does not use a QApplication-object and I am getting the typical "QWidget: Must construct a QApplication before a QPaintDevice" error message.

    Is it possible to have a console application capable of showing a dialog or form if required? What is the correct way of doing this?

    Thank you for your help!

  2. #2
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QT dialogs in a console application

    What do you mean by "console application", then?

  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: QT dialogs in a console application

    You could make the application instantiate a QApplication when it is run with a certain commandline switch.
    Or make the distinction based on build flags at compile time.

    Cheers,
    _

  4. #4
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: QT dialogs in a console application

    Quote Originally Posted by anda_skoa View Post
    You could make the application instantiate a QApplication when it is run with a certain commandline switch.
    Or make the distinction based on build flags at compile time.
    I wrote one app in which I wanted both a GUI interface as well as a command line capability to be used for automating tasks. I decided to implement the core functionality in a shared library. I used a subdirs project, with one subproject for the lib, one for the command line version, and one for the GUI. Both command line and GUI versions used the classes/methods from the shared library, so the command line and GUI executable's were just really thin wrappers, etc.

    I'm not saying that works for everyone, but in my case, I preferred that approach over a single executable that had multiple personalities.
    I write the best type of code possible, code that I want to write, not code that someone tells me to write!

Similar Threads

  1. Closing Modeless Dialogs from MainWindow Application
    By jeffd589 in forum Qt Programming
    Replies: 1
    Last Post: 12th February 2013, 00:36
  2. Replies: 8
    Last Post: 23rd August 2012, 19:28
  3. about console application
    By jirach_gag in forum Qt Programming
    Replies: 2
    Last Post: 5th January 2012, 11:39
  4. Replies: 2
    Last Post: 21st November 2010, 18:03
  5. Replies: 0
    Last Post: 23rd April 2010, 17:25

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.