functions. If you are serious about mastering Qt Designer, it’s worth spending some
time working through the Qt Assistant
documents. In particular, click the
Contents tab, and open the Qt
Designer Manual, which
includes a wealth of useful
tutorials and examples.
The second push button also
must have its member function
created (Listing 4). Again, the
code shown here is more complex than a simple application
needs to be, but it shows a
very useful feature: calling a
command-line program.
Let’s work through the
code. Note how the text box
on-screen is cleared. The ui.textEdit gives you access
to the visual component, and
the member function clear() }
is called. QbyteArray is an
advanced C++ string type
object. The QProcess object
enables you to run a command-
line program. First, the working
directory is set, and then the
command started. If it returns
within 300 milliseconds, the
result is written into the
textEdit box; otherwise, the
command is terminated, and
the default error message is
printed. Note that the returned
text from the command line may
have nonprinting characters,
such as line feeds. To solve this problem,
look up the QbyteArray member function
simplified() in Qt Assistant.
To respond to the menu on the
Listing 4. Second Push Button