PDA

View Full Version : QT dialogs in a console application



FiddlerJoe
5th August 2015, 16:08
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!

yeye_olive
5th August 2015, 17:10
What do you mean by "console application", then?

anda_skoa
5th August 2015, 21:14
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,
_

jefftee
6th August 2015, 00:00
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.