hello.show();
A widget is never visible when you create it. You must callQWidget::show() to make it visible.
return app.exec();}
This is where
main()
Environment Variables
If you are developing Qt applications at the command line, you need to ensure that the Qt libraries andexecutables are accessible to your environment by prepending the path to Qt's
bin
directory to your
PATH
variable; this is described in theInstallationinstructions for your platform.On Windows, this is automatically done for you if you get your command line prompt from the
Start>All Programs>Qt
menu. If you get your command line prompt with
Start>Run>Command
, you have to set the
PATH
variable there yourself.
Building an application
The tutorial examples are located in the Qt
examples/tutorials/tutorial
directory. If you installed a binary Qt package, pre-built examples were installed as well. If you built Qt yourself, the examples were built at the sametime. In either case, there is a lot to be learned about using Qt by modifying and building the examples yourself.Assuming you have copied an example's
.cpp
and
.h
files to an otherwise empty directory, and you have madeyour changes there, the next step is to create a Qt makefile in that directory. To create a Qt makefile, useqmake,the build tool supplied with Qt. Run the following two commands in the directory containing your modifiedsources to create the makefile.
qmake -projectqmake
The first command tells qmake to create a project (
.pro
) file. The second command tells qmake to use the
.pro
file to create a platform-specific makefile. Now you can just run
make
(
nmake
if you are using Visual Studio) to compile the program, and then you canrun your first Qt application!
Running this example
When you run the example, you will see a small window showing a single button. On the button you can readthe famous words: "Hello world!"
Exercises
Try to resize the window. Click the button. If you are running X11, try running the program with the
-geometry
option (e.g.,
-geometry 100x200+10+20
).
Qt Tutorial 2 - Calling it Quits
Add a Comment