The NetBeans IDE supports creating, building, running, and debugging of Qt projects
without leaving the IDE. Qt tools such as qmake, moc, and uic are launched automatically as needed.
You don't need to think (and probably even know) about them.
Installing the Qt Software
When using the NetBeans IDE with Qt, you do not need the full Qt SDK on non-Windows
platforms. You can install your compilers as described in
Configuring the NetBeans IDE for C/C++/Fortran, and then you can download the Qt libraries and tools, also known as the Qt framework.
On Windows, however, you should install the Qt SDK to avoid potential problems.
Setting Up Qt for NetBeans IDE on Windows
The Qt 4.6.2 SDK includes the MinGW environment and gcc 4.4 compiler.
This bundled MinGW works best with Qt, so you should use it
instead of another MinGW version or Cygwin.
You should install your compilers separately. Compilers are not included in the Qt SDK as they are
After you install the Qt packages, make sure that Qt tools are
available from the command line. Typing qmake -v in a terminal
should print Qt version information rather than an error message. If qmake
is not found, add your-Qt-installation-dir/bin to your PATH environment variable.
The path to qmake should be something similar to /home/user/qtsdk-2010.02/qt/bin if you download
In this tutorial we'll create a simple "Hello World" Qt application, similar to
the Hello Qt World sample, which you can find in
Samples->C/C++->Hello Qt World.
First, create a new project. Choose C/C++ Qt Application in
the New Project dialog and click Next >.
In the next dialog change project name and location if needed.
Check Create Main File and click Finish.
Our newly created project looks like this:
Right-click the project node and select Properties to open the Project Properties dialog. Click the Qt category.
Advanced users can tweak many things in the Qt project properties, but we will leave everything as is.
Next we'll create a dialog. Right-click on Resource Files and
select New->Qt Form...
In the New Qt Form dialog, type HelloForm as the Form Name, and select Dialog without Buttons as the
Form Type. Check Create C++ wrapper class, and click Finish.
Three files are created (HelloForm.ui, HelloForm.cpp,
HelloForm.h), and NetBeans automatically opens Qt Designer for you to
edit the new form (HelloForm.ui).
Use your GUI skills to create a form similar to that shown below. The form should
contain two QLineEdit widgets. The first widget should be named
nameEdit, and the second widget should be named helloEdit.
When you are finished creating the form, close Qt Designer. The project looks as follows:
All the newly created HelloForm files are placed in the same Resource Files
logical folder. If you prefer to have CPP files in Source Files and H
files in Header Files — just drag and drop them to the desired logical
There is a small question mark in the Projects tab indicating
broken #include directives. The setupUi underlined with red is a
consequence of this fact.
The broken #include directive is in HelloForm.h: #include ui_HelloForm.h.
Indeed, there is no ui_HelloForm.h yet. The include file will be
generated with the first build of the project. This is how the Qt build
system works. Just click on the Build Main Project button on the
toolbar, and the error should disappear.
Now open main.cpp and insert two lines of code responsible for
creation and displaying of HelloForm. Don't forget to include
Run the application and see how it displays the window that you
created in Qt Designer.
Anything can be typed in the text field, but
nothing happens. Let's make our application show a greeting message that
includes the name entered in the text field.