Most Qt tutorials seem to assume you want to use Qt Creator. This shows you how to build Qt apps on the command line, meaning you can experiment much quicker while feeling that you're in control.
Create a directory
foo and then put the code below into
qmake, set up a new Qt project and create a GNU makefile.
With newer versions of Qt, you have to edit
foo.pro after creating it. Add
qt += WIDGETS to be able to compile:
Now, generate a makefile:
If you use other parts of Qt, for example networking, you may have to add
additional such lines (
QT += networking). In that case, you have to recreate
the makefile with the above command.
Now you can simply
make the app.
It depends on the system what the final binary will be called. On Mac OS X, it
foo.app, and on Windows I guess it will be
foo.exe. To open the
application bundle on OS X, do
The result should look similar to the image below.
You'll soon want to use the meta-object compiler to be able to play with slots
and signals. The makefile already supports this, but you have to explicitly
call the target to build the
.moc files. Type
to build them. If you copy the below code, this command will create
After that, you need to
#include "foo.moc" at the end of
foo.cpp to make
sure the linker doesn't complain about missing vtables.
Here's a really simple example to get you going:
This will give you a window with a single button, which opens a pop-up window when clicked.
You can hack the makefile to automatically build
foo.moc, but since it's
automatically generated, I suggest you either just build the mocables
explicitly, or find out how to add the moc targets to