How to Develop Qt Applications in the Oracle Developer Studio IDE

by Igor Nikiforov, August 2012 (updated by Dmitry Zharkov, June 2016)

Quick tutorial for creating your first Qt application in the Oracle Developer Studio Integrated Development Environment (IDE).


Qt is a framework for creating Web applications that can be deployed on multiple platforms, including desktop systems and mobile devices. The Qt SDK includes the libraries, some tools, and an IDE called Qt Creator. However, you can use the Oracle Developer Studio IDE instead to create Qt applications if you have the Qt SDK and GNU compilers. The Qt version must be at least Qt4.

The Oracle Developer Studio 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 (or probably even know) about them.

Installing the Qt Software

Before you create Qt applications, you must install the Qt4 SDK.

Setting Up Qt for Oracle Developer Studio IDE on Linux

To use Qt in the Oracle Developer Studio IDE on Linux, be aware of the following:

  • You must use the GNU tool collection (also known as the GNU compiler collection or GCC) with Qt because the Oracle Developer Studio compilers are not supported by Qt on Linux. The IDE does not provide the GNU compilers, but it finds them if they are installed on your system and included on your path. If GNU tools are not present, you should be able to install the gcc packages from the Linux software repository.
  • For many Linux distributions, you can also install Qt from the software repository. See your Linux documentation for more information.
  • You can also download the Qt software for your Linux platform from http://qt.nokia.com/downloads. You can also download the source and build it yourself if you want.
  • When you install the Qt SDK using the installer, the Qt Designer might not be selected for installation by default. You must choose the custom installation mode and select the Qt Designer for installation.
  • After you install the Qt software, 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/Desktop/Qt/474/gcc/bin/ if you download the Qt SDK.
  • When the Qt tools are available from the command line, proceed to the "Creating a Simple Qt Application" section of this article.

Setting Up Qt for Oracle Developer Studio IDE on Oracle Solaris Platforms

To use Qt in the Oracle Developer Studio IDE on Oracle Solaris, be aware of the following:

  • You must build Qt on Oracle Solaris because binaries for Qt are not available for Oracle Solaris platforms. You can get the Qt sources from the official Qt source code repository.
  • You need to use Git to get the Qt source code. For information about Git, see Git Installation.
  • For information about getting the Qt source code and building it, see Get the Source Code.
  • After you build the Qt software, 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.

Creating a Simple Qt Application

In this tutorial, you create a simple "Hello World" Qt application. When you are finished, the application will be similar to the Hello Qt World sample, which you can find in the IDE project samples.

  1. Click the New Project button, and in step 1 of the New Project wizard, select the C/C++/Fortran category and the C/C++ Qt Application project, and then click Next.

    Figure 1

    Figure 1. New Project Wizard with C/C++ Qt Application Selected

  2. In step 2 of the wizard, select Create Main File if it is not already selected.

    If you are using Linux, set Tool Collection to GNU, and click Finish.

    Note: In the Figure 2, Tool Collection is set to Oracle Developer Studio. This tool collection will work only if you are using Qt software that you built on Oracle Solaris with the Oracle Developer Studio compiler.

    Figure 2

    Figure 2. Project Name and Location Step

    The newly created Qt_Application project opens in the IDE and looks like Figure 3:

    Figure 3

    Figure 3. Open Qt Application Project

  3. Right-click the Qt Application project and select Properties to open the Project Properties dialog box; then click the Qt category.

    Figure 4

    Figure 4. Qt Application Project's Properties

    Advanced users can tweak many things in the Qt project properties, but for now you should leave everything as is.

    Note: If you are developing on Oracle Solaris with Oracle Developer Studio compilers, make sure that the Qmake Spec option in the Expert section of the properties contains the value solaris-cc.

  4. Right-click the Resource Files folder and select New -> Qt Form to begin creating a dialog box for the application.

    Figure 5

    Figure 5. Context Menu for Creating a New Qt Form

  5. In the New Qt Form dialog box, type HelloForm in the Form Name field, and select Dialog without Buttons from the Form Type list. Select Create C++ wrapper class, and click Finish.

    Figure 6

    Figure 6. New Qt Form Dialog Box with Selections

    Three files are created (HelloForm.ui, HelloForm.cpp, HelloForm.h), and the IDE automatically opens Qt Designer for you to edit the form HelloForm.ui.

    Figure 7

    Figure 7. Qt Designer Window with a Blank New Form

  6. Create a form similar to that shown in Figure 8 by dragging and dropping widgets from the panel on the left to the form in the middle.

    You should place two QLineEdit widgets in the form, name the first widget nameEdit, and name the second widget helloEdit.

    Figure 8

    Figure 8. Qt Designer with Form You Created

  7. When you are finished creating the form, close Qt Designer.

    The project looks like Figure 9:

    Figure 9

    Figure 9. New Project with Files

    All the newly created HelloForm files are placed in the same Resource Files logical folder. If you prefer to have .cpp files in the Source Files folder and .h files in the Header Files folder, just drag and drop them to the desired logical folder.

    A question mark on the QtApplication icon in the Projects tab indicates the project has broken #include directives. The line #include "HelloForm.h" is highlighted to show where the problem occurs.

    The broken #include directive is in the HelloForm.h file: #include ui_HelloForm.h. Indeed, there is no ui_HelloForm.h file yet. The ui_HelloForm.h include file will be generated with the first build of the project. This is not really an error; it is how the Qt build system works. Just click the Build Main Project button on the toolbar, and the error should disappear.

  8. Now open main.cpp and insert two lines of code to create and display HelloForm.

    In Figure 10, the new lines you need are shown in lines 17 and 18:

    HelloForm form;
    form.show();
    

    Don't forget to include HelloForm.h, as shown in line 9.

    Figure 10

    Figure 10. Code Added to main.cpp File

  9. Run the application and see how it displays the window that you created in Qt Designer.

    You should find that you can type anything in the text field, but nothing happens when you do. To see something happen, you add to the application to have it respond with a greeting message that includes the name entered in the text field.

    To do this, you need to define a slot and connect it to a textChanged signal fired by the text field.

    To learn more about Qt signals and slots, see Signals and Slots.

  10. Go to HelloForm.h and declare this slot, as shown in line 18 in Figure 11.

    Figure 11

    Figure 11. Slot Declaration in HelloForm.h File

  11. Then go to HelloForm.cpp and insert the slot definition, as shown at line 17 in the Figure 12.

    Figure 12

    Figure 12. Code for Slot Definition in HelloForm.cpp File

  12. And, finally, connect the signal with the slot by inserting some code into the HelloForm constructor.

    In Figure 13, the code is inserted at lines 12 through 13 of HelloForm.cpp.

    Figure 13

    Figure 13. Code Added to HelloForm.cpp to Connect the textChanged Signal

  13. Now run the application and enter your name, and the application should say hello to you.

    Figure 14

    Figure 14. Application Response

See Also

See the following locations for more information:

About the Author

Igor Nikiforov has been working for Oracle and Sun Microsystems for more than four years. His current responsibilities include development of the Oracle Developer Studio IDE and NetBeans. Before Oracle, Igor developed enterprise applications including some municipal IT projects for the city of Saint Petersburg, Russia.

Revision 1.1, June 2016
Revision 1.0, August 2012

facebook banner twitter banner