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. This article shows how to configure
NetBeans IDE to use Qt 4.8 and create a simple Qt application.
Installing the Qt Software for Use in NetBeans IDE
You must install the Qt software and configure NetBeans to use it before creating Qt applications in the IDE.
Important: You must use Qt 4.8 to follow this tutorial.
You must edit your PATH environment variable in Windows to add the paths to the binaries for Qt, MinGW, and MSYS.
If you installed to the default locations, the paths are:
To add the paths to your Path environment variable:
Open the Environment Variables window:
On Windows XP and Windows 2000: Right-click My Computer > Properties > Advanced tab >
Environment Variables button.
On Windows Vista and Windows 7: Right-click My Computer > Properties >
Advanced System Settings link > Environment Variables button.
In the Environment Variables window, select the Path variable in the Systems Variable
section and click Edit.
At the end of the path, insert a semi-colon and add the paths to the executables for
Qt, MinGW, and MSYS. Use semi-colons between the paths and do not use any spaces.
Be careful not to remove anything already on your PATH or your computer might not work correctly.
When you are finished, your path should look similar to the following:
You need to create a new tool collection that uses MinGW compilers, the MSYS commands, and Qt commands.
To create a new tool collection:
Start NetBeans IDE and open the Services window by choosing Window > Services.
Expand the C/C++ Build Hosts node and the localhost node, and right click the Tool Collections node and select
Add New Tool Collection.
Specify the MinGW installation's bin directory as the tool collection's Base Directory
(for example, C:\mingw\bin).
The Tool Collection Family and Tool Collection Name should be automatically filled in as MinGW.
Change the Tool Collection Name to MinGW_Qt and click OK.
Right-click the new MinGW_Qt tool collection under the Tool Collection node in the Services window and choose Properties.
The paths to the tools should look similar to the following figure.
Check the paths for the Make Command and QMake Command and correct them if needed.
The Make Command should be C:\MinGW\MSYS\1.0\bin\make.exe command, and the
QMake Command command should be C:\Qt\4.8.5\bin\qmake.exe.
Click the Default button while MinGW_Qt is selected to make it the default tool collection.
In this tutorial you 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.
These instructions are written for Windows platforms. Users on Linux, Mac, and Solaris platforms can perform the
same steps using a GNU tool collection where the path to qmake is correctly specified.
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 select the MinGW_qt tool collection, then click Finish.
Your newly created project should look similar to the following figure:
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 for this tutorial you should leave everything as it is.
Click the Run category and set the Console Type property to External Terminal, then click OK.
Next you can create a form. 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 the IDE 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. Add to the form two QLineEdit widgets
and change the name of the first widget to nameEdit, and change the name of the second widget to helloEdit.
When you are finished creating the form, save it and close Qt Designer. The project looks as shown in the following figure.
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
You should see a small question mark in the Projects tab to indicate the presence of
broken #include directives. The setupUi underlined with red is a
consequence of the broken #include ui_HelloForm.h directive, which occurs in the HelloForm.h file.
The ui_HelloForm.h include file does not actually exist yet and it will be generated with the first build of the project. This is how the Qt build
Click the Build Project button on the toolbar and the error should disappear when the ui_HelloForm.h file is generated.
Open main.cpp and insert two lines of code that are responsible for
creation and displaying of HelloForm as shown in lines 17 and 18 in the figure below.
Don't forget to include HelloForm.h as shown in line 9.
Click the Run button in the tool bar to run the application.
First you see a terminal window and then the dialog box that you
created in Qt Designer.
Type something in the text field and press Enter, and you should see that nothing happens.