From e02e31c8b9d854cd62cbe9799228f6e08e882773 Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Mon, 5 Dec 2011 22:04:08 -0600 Subject: Sync with latest script --- doc/html/designer-manual-6.html | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'doc/html/designer-manual-6.html') diff --git a/doc/html/designer-manual-6.html b/doc/html/designer-manual-6.html index 9c9845df8..e6825b8ef 100644 --- a/doc/html/designer-manual-6.html +++ b/doc/html/designer-manual-6.html @@ -95,7 +95,7 @@ int main( int argc, char *argv[] ) }

Note that we're including creditformbase.h and instantiating a CreditFormBase object; once we've written our subclass we'll replace the header with our subclass, creditform.h, and instantiate a CreditForm.

-

We can now generate the application with qmake, e.g. qmake -o Makefile credit.pro, make it and run it. The form should run fine, but doesn't yet have the behaviour we retquire.

+

We can now generate the application with qmake, e.g. qmake -o Makefile credit.pro, make it and run it. The form should run fine, but doesn't yet have the behaviour we require.

Creating the Subclass

We need to create a header and an implementation file for our subclass. The code for our subclass is minimal. The header file is qt/tools/designer/examples/credit/creditform.h:

    #include "creditformbase.h"
@@ -174,7 +174,7 @@ FORMS      = mainform.ui
 LANGUAGE    = C++
 INCLUDEPATH += $(QTDIR)/tools/designer/uilib
 
-

We do not include the creditformbase.ui file since this file will be read at runtime, as we'll see shortly. We must include the tqui library since the functionality we retquire is not part of the standard TQt library.

+

We do not include the creditformbase.ui file since this file will be read at runtime, as we'll see shortly. We must include the tqui library since the functionality we require is not part of the standard TQt library.

Creating main.cpp

The main.cpp is quite standard. It will invoke the form we're going to create in TQt Designer as its main form. This form will then load and execute the dynamic dialog.

    #include <qapplication.h>
@@ -217,7 +217,7 @@ INCLUDEPATH += $(QTDIR)/tools/designer/uilib
         delete creditForm;
     }
 
-

The create() function is a static TQWidgetFactory function. It loads the specified .ui file and returns a pointer to the toplevel TQWidget created from the .ui file. We have cast the pointer to TQDialog since we know that the creditformbase.ui file defines a TQDialog. After creating the dialog we exec() it. If the user clicked OK the dialog returns Accepted and we enter the body of the if statement. We want to know the amount of credit that the user selected. We call the child() function on the dialog passing it the name of the widget we're interested in. The child() function returns a pointer to the widget with the name we passed, or returns 0 if no widget of that name was found. In the example we call child() to get a pointer to the 'amountSpinBox'. If the pointer we get back is not 0 we set the rating text to the amount in the dialog's spin box. At the end we delete the dynamic dialog. Deleting the dialog ensures that we free up its resources as soon as it is no longer retquired.

+

The create() function is a static TQWidgetFactory function. It loads the specified .ui file and returns a pointer to the toplevel TQWidget created from the .ui file. We have cast the pointer to TQDialog since we know that the creditformbase.ui file defines a TQDialog. After creating the dialog we exec() it. If the user clicked OK the dialog returns Accepted and we enter the body of the if statement. We want to know the amount of credit that the user selected. We call the child() function on the dialog passing it the name of the widget we're interested in. The child() function returns a pointer to the widget with the name we passed, or returns 0 if no widget of that name was found. In the example we call child() to get a pointer to the 'amountSpinBox'. If the pointer we get back is not 0 we set the rating text to the amount in the dialog's spin box. At the end we delete the dynamic dialog. Deleting the dialog ensures that we free up its resources as soon as it is no longer required.

We used the child() to gain access to a widget within the dynamic dialog, passing it the name of the widget we were interested in. In some situations we might not know what a widget is called. We can access the first widget of a specified class by calling child() with a null widget name and a classname, e.g. child(0,"TQPushButton"). This will return a pointer to the first TQPushButton it finds (or 0 if there isn't one). If you want pointers to all the widgets of a given class you can call the TQObject::queryList() function, passing it the name of the class. It returns a TQObjectList pointer which points to every object in the dialog that is derived from the given class. See the online TQObject documentation for further details.

Implementing Slots for Dynamic Dialogs

There is one outstanding issue that we haven't addressed: the dynamic dialog does not have the behaviour of the original credit dialog because we have not implemented the setAmount() slot. We can implement slots for dynamic dialogs by creating a TQObject subclass. We then create an instance of this subclass and pass a pointer to it to the TQWidgetFactory::create() function which will connect the dynamic dialog's signals to the slots implemented in our subclass.

@@ -260,7 +260,7 @@ private: };

Our class must be a TQObject subclass and because we're using signals and slots it must include the Q_OBJECT macro. We declare a function and the setAmount() slot that we wish to implement as well as a private TQDialog pointer.

-

The implementation retquires the header files of the classes it uses:

+

The implementation requires the header files of the classes it uses:

    #include <qradiobutton.h>
     #include <qspinbox.h>
     #include "receiver.h"
-- 
cgit v1.2.1