Eclipse Qt Signal Slot Editor

The Calendar Widget example displays a QCalendarWidget and lets the user configure its appearance and behavior using QComboBoxes. We connect the signals and slots. Slot updates the Current Date editor. We also need to react when the user changes the Minimum Date and Maximum Date editors. Here is the createTextFormatsGroup function.

  1. Qt Signal Slot Connect
  2. Qt Signal Slot Thread
  3. Qt Slots

Home > Articles > Programming > C/C++

  1. Using Qt Jambi in the Eclipse IDE
Example

Mar 24, 2011  Thanks for your fast reply, but I'm newbie with this: eclipse, Qt and not an expert with C (I used to develop with C and Java). Using Eclipse. Can any tell me: - How to create a slot for the function changeText? Where do I've to write it to be available form the 'Signal Slot Editor' (if really is better to configure it as a slot). Adding slot for a signal of a widget is easy: right click on it and select 'go to slot'. But how can I remove the slot created for a button (like onpushButtonclicked) from the Qt designer.

< BackPage 3 of 4Next >
This chapter is from the book
C++ GUI Programming with Qt4, 2nd Edition

This chapter is from the book

This chapter is from the book

Using Qt Jambi in the Eclipse IDE

The Eclipse IDE ('Eclipse' for short) is one of the key pieces of software in the Eclipse family of more than sixty open source projects. Eclipse is very popular with Java programmers, and since it is written in Java, it runs on all major platforms. Eclipse displays a collection of panels, called views. Many views are available in Eclipse, including navigator, outline, and editor views, and each particular collection of views is called a perspective.

To make Qt Jambi and Qt Designer available inside Eclipse, it is necessary to install the Qt Jambi Eclipse integration package. Once the package is unpacked in the right location, Eclipse must be run with the -clean option to force it to look for new plugins, rather than relying on its cache. The Preferences dialog will now have an extra option called 'Qt Jambi Preference Page'. It is necessary to go to this page and set Qt Jambi's location, as explained in http://doc.trolltech.com/qtjambi-4.3.2_01/com/trolltech/qt/qtjambi-eclipse.html. Once the path has been set and verified, Eclipse should be closed and restarted for the changes to take effect.

The next time we start Eclipse and click File|New Project, the New Project dialog that pops up will offer two kinds of Qt Jambi project: Qt Jambi Project and Qt Jambi Project (Using Designer Form). In this section, we will discuss both of these project types by presenting a Qt Jambi version of the Go to Cell example developed in Chapter 2.

To create a Qt Jambi application purely in code, click File|New Project, choose 'Qt Jambi Project', and go through each page of the wizard. At the end, Eclipse will create a project with a skeleton .java file with a main() method and a constructor. The application can be run from within Eclipse using the Run|Run menu option. Eclipse shows syntax errors in the left margin of the editor, and shows any errors that occur at run-time in a console window.

Creating a Qt Jambi application that uses Qt Designer is very similar to creating a pure code application. Click File|New Project, and then choose 'Qt Jambi Project (Using Designer Form)'. Again, a wizard will appear. Call the project 'JambiGoToCell', and on the last page, specify 'GoToCellDialog' as the class name and choose 'Dialog' as the form type.

Once the wizard has finished, it will have created GoToCellDialog.java and also a Java user interface file GoToCellDialog.jui. Double-click the .jui file to make the Qt Designer editor visible. A form with OK and Cancel buttons will be shown. To access Qt Designer's functionality, click Window|Open Perspective|Other, then double-click Qt Designer UI. This perspective shows Qt Designer's signal–slot editor, action editor, property editor, widget box, and more, as shown in Figure C.2.

Figure C.2 The Go to Cell dialog in Eclipse

To complete the design, we perform the same steps as in Chapter 2 (p. 24). The dialog can be previewed as it could be within Qt Designer, and since Eclipse generates skeleton code it is also possible to run it by clicking Run|Run.

The final stage is to edit the GoToCellDialog.java file to implement the functionality we need. Two constructors are generated by Eclipse, but we only want one of them, so we delete the parameterless constructor. In the generated main() method, we must pass null as the parent to the GoToCellDialog constructor. Also, we must implement the GoToCellDialog(QWidget parent) constructor, and provide a on_lineEdit_textChanged(String) method that is called whenever the line editor's textChanged() signal is emitted. Here is the resulting GoToCellDialog.java file:

Eclipse takes care of invoking juic to convert GoToCellDialog.jui into Ui_GoTo-CellDialogClass.java, which defines a class called Ui_GoToCellDialogClass that reproduces the dialog we designed using Qt Designer. We create an instance of this class and keep a reference to it in a private field called ui.

Qt Signal Slot Connect

Slots

In the constructor, we call the Ui_GoToCellDialogClass's setupUi() method to create and lay out the widgets and to set their properties and signal–slot connections, including automatic connections for slots that follow the naming convention on_objectName_signalName().

A convenient feature of the Eclipse integration is that it is easy to make QWidget subclasses available in the widget box to be dragged on to forms. We will briefly review the LabeledLineEdit custom widget, and then describe how to make it available in Qt Designer's widget box.

When we create custom widgets for use with Qt Designer, it is often convenient to provide properties that the programmer can change to customize the widget. The screenshot in Figure C.3 shows a custom LabeledLineEdit widget in a form. The widget has two custom properties, labelText and editText, that can be set in the property editor. In C++/Qt, properties are defined by means of the Q_PROPERTY() macro. In Qt Jambi, introspection is used to detect pairs of accessor methods that follow the Qt naming convention xxx()/setXxx() or the Java naming convention getXxx()/setXxx(). It is also possible to specify other properties and to hide automatically detected properties using annotations.

The first import declaration is needed to access Qt Jambi's @QtPropertyReader() and @QtPropertyWriter() annotations, which let us export properties to Qt Designer.

For read-only properties, we can simply use the @QtPropertyReader() annotation and provide a getter method. Here we want to provide read-write properties, so each has a getter and a setter. For this example, we could have omitted the annotations, since the accessor methods follow the Qt naming convention.

The constructor is quite conventional. To be eligible for use in the widget box, we must provide a constructor that takes a single QWidget argument.

Eclipse generates the main() method automatically. We have passed null as the argument to the LabeledLineEdit constructor and added a line to set the label's text property.

Once we have a custom widget, we can add it to a project by copying its .java file into the project's src in the package explorer. Then we invoke the project's Properties dialog and click the Qt Designer Plugins page. This page lists all the suitable QWidget subclasses that are in the project. We just need to check the Enable plugin checkbox for any of the subclasses that we want to appear in the widget box and click OK. The next time we edit a form using the integrated Qt Designer, the widgets we have added to the project as plugins will appear at the bottom of the widget box in a separate section.

Qt Signal Slot Thread

This concludes our brief introduction to using Eclipse for Qt Jambi programming. Eclipse provides a powerful and functional IDE with many conveniences for software development. And with the Qt Jambi integration in place, it is possible to create Qt Jambi applications, including those that use Qt Designer, completely within the Eclipse environment. Trolltech also provides a C++/Qt Eclipse integration with most of the same benefits as the Qt Jambi one.

Related Resources

Qt Slots

  • Book $31.99
  • Book $35.99
  • Book $43.99