[Interest] Design idioms for QtCore applications

Karl Ruetz karl.ruetz at ruetzdogz.com
Fri Feb 8 15:37:23 CET 2013


 

My company has been writing server type applications in Qt for about
10 years. While these do not involved acquiring data from the command
line, they do have to detect "work to do" in some fashion through the
event loop. In your case, it seems as though your "to do" list is coming
through the command line. 

I would suggest you take a look at the
Fortune examples. They might give you a hint as to how this might be
accomplished. 

Regards, 

Karl 

On 2013-02-08 06:02, K. Frank wrote:


> Hello List!
> 
> I am playing around with non-gui, "QtCore"
applications,( i.e., applications
> that have #include <QtCore> rather
than #include <QtGui>).
> 
> (To date, I have been using Qt for gui's.
If an app hasn't had a gui, I
> didn't use Qt, and I would write the
non-gui "business logic" in my
> gui apps in Qt-independent code, adding
a little translation layer
> if I needed to convert stuff to things like
QString.)
> 
> I'm looking for general advice on the design philosophy
for QtCore
> apps, how to use events, and design idioms for simple
QtCore
> apps.
> 
> For example, following much of the Qt example code,
I typically
> use the following idiom for gui apps:
> 
> #include
<QApplication>
> #include "my_main_window.h"
> int main (int argc, char
*argv[]) {
> QApplication a(argc, argv);
> MyMainWindow mainWindow;
>
mainWindow.show();
> return a.exec();
> }
> 
> (For me, MyMainWindow is
typically a Qt-Designer built class.)
> 
> I never really thought much
about how the gui events processed
> by MyMainWindow interact with the
a.exec() event loop. I just
> chalked it up to the "magic" of the gui
framework.
> 
> By analogy, I would like to do something like:
> 
>
#include <QtCore>
> #include "my_non_gui_class.h"
> int main(int argc,
char *argv[]) {
> QCoreApplication a (argc, argv);
> MyNonGuiClass
mainObject;
> return a.exec();
> }
> 
> Inside of MyNonGuiClass I might
like to do something like
> 
> while (dontStop) {
> std::string
command;
> std::cin >> command;
> processCommand (command);
> }
> 
>
but, of course, the call to "std::cin >>" would block until input is
provided.
> 
> I think part of what I'm missing is the connection
between the event
> loop, "a.exec()", and processing console input
without blocking.
> 
> (I understand that one way to deal with blocking
calls is to wrap them
> in their own threads, but I'm looking for an
approach more in the spirit
> of a simple, single-threaded Qt-gui
hello-world app.)
> 
> I hope it's clear what I'm trying to ask.
> 
>
Any thoughts or advice on both how to do it and how it works under
> the
hood would be appreciated.
> 
> K. Frank
>
_______________________________________________
> Interest mailing
list
> Interest at qt-project.org
>
http://lists.qt-project.org/mailman/listinfo/interest [1]



Links:
------
[1]
http://lists.qt-project.org/mailman/listinfo/interest
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20130208/67df8415/attachment.html>


More information about the Interest mailing list