O'Reilly logo

Qt 5 Projects by Marco Piccolino

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Defining application output upon success

What should happen if, after instructing the application to run the usecase, this ends successfully?

Let's say we want to print the list of grocery items, each item displaying its name. We achieve this by:

  1. Creating an object that handles text output
  2. Creating a slot that writes the list to the text output
  3. Connecting the usecase's success signal to the slot

For the text output object, we use the convenient QTextStream (http://doc.qt.io/qt-5.9/qtextstream.html) class and connect it with the console's stdout device:

// tui/main.cpp...QTextStream cout(stdout);...

For the slot, we can make use of a C++11 lambda, which can be defined directly as the third argument to connect:

// tui/main.cpp...QObject

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required