[Interest] Design idioms for QtCore applications

K. Frank kfrank29.c at gmail.com
Fri Feb 8 16:15:39 CET 2013


Hi Jason!

On Fri, Feb 8, 2013 at 9:20 AM, Jason H <scorp1us at yahoo.com> wrote:
> I've written a number of server applications.
>
> They work the same, you just inherit from QCoreApplication and make sure you
> have events.

Ah, okay.

To make sure I understand the suggestion:

Rather than instantiate separately (for example in my main()) both an
actual (non-subclassed) QCoreApplication and a business-logic class
that (presumably) inherits from QObject, are you saying that I should
inherit my main business-logic class for QCoreApplication, instantiate
that, and then call its exec()?

So this idiom is a little different that the gui idiom in the example in my
original post where I instantiate a QApplication and a MyMainWindow
class separately.

Is there a gui idiom analogous to what you are suggesting where I
inherit my main window class somehow from QApplication, and call
its exec() directly?

> It would help to know what you're trying to do, but as long as you're not
> just processing command line arguments and exiting, you're going to need
> some way to acquire work (socket maybe?) and then do that work. Look at a
> QTcpServer example.

Well, truth be told, I'm not trying to do anything.  Or, more seriously,
I'm trying to learn, so that I get a sense of the Qt-approved way of doing,
so that I get a sense of what one can do with non-gui Qt apps and
when I might want to use them.

That is, I'm just playing around right now.

The kind of thing I'm thinking of, hypothetically, is some kind of server
that responds to events coming in over a socket (maybe sometimes
writing to that or another socket), but also responds to commands
typed into the console.  (These might be more along the lines of
management-control commands.)  So the first thing I thought I might
try is to build a toy app that uses the event loop, but responds initially
only to command-line input.


Thanks for your thoughts.


K. Frank


> ________________________________
> From: K. Frank <kfrank29.c at gmail.com>
> ...
>
> Hello List!
>
> I am playing around with non-gui, "QtCore" applications,( i.e., applications
> that have #include <QtCore> rather than #include <QtGui>).
> ...
> I'm looking for general advice on the design philosophy for QtCore
> apps, how to use events, and design idioms for simple QtCore
> apps.
> ...



More information about the Interest mailing list