summaryrefslogtreecommitdiffstats
path: root/doc/html/designer-manual-6.html
diff options
context:
space:
mode:
Diffstat (limited to 'doc/html/designer-manual-6.html')
-rw-r--r--doc/html/designer-manual-6.html54
1 files changed, 27 insertions, 27 deletions
diff --git a/doc/html/designer-manual-6.html b/doc/html/designer-manual-6.html
index 8881aae6d..cbe5af6f1 100644
--- a/doc/html/designer-manual-6.html
+++ b/doc/html/designer-manual-6.html
@@ -113,8 +113,8 @@ int main( int argc, char *argv[] )
</pre>
<!-- index Macros!TQ_OBJECT --><!-- index TQ_OBJECT --> <p>We've declared the slot, <tt>setAmount()</tt>, that we created in <em>TQt Designer</em>. The <tt>TQ_OBJECT</tt> macro is included because it is essential for classes that use signals and slots.</p>
<p>The implementation in <tt>qt/tools/designer/examples/credit/creditform.cpp</tt> is simple:</p>
-<pre> #include &lt;<a href="qradiobutton-h.html">ntqradiobutton.h</a>&gt;
- #include &lt;<a href="qspinbox-h.html">ntqspinbox.h</a>&gt;
+<pre> #include &lt;<a href="tqradiobutton-h.html">tqradiobutton.h</a>&gt;
+ #include &lt;<a href="tqspinbox-h.html">tqspinbox.h</a>&gt;
#include "creditform.h"
CreditForm::CreditForm( <a href="tqwidget.html">TQWidget</a>* parent, const char* name,
@@ -200,73 +200,73 @@ INCLUDEPATH += $(TQTDIR)/tools/designer/uilib
<li><!-- index Signals and Slots!Connecting to Close a Dialog --><p>We'll now handle the signals and slots connections. Invoke the <em>View and Edit Connections</em> dialog and connect the credit dialog button's clicked() signal to a new creditDialog() custom slot (which is created by clicking the <b>Edit Slots...</b> button). Now connect the Quit button's<!-- index clicked() --> <tt>clicked()</tt> signal to the dialog's<!-- index accept() --> <tt>accept()</tt> function.</p>
</ol><p>Save the form and call it <tt>mainform.ui</tt>. (Press <b>Ctrl+S</b> and enter the filename.) In the next section we'll write the code for loading and launching the dynamic dialog directly in <em>TQt Designer</em>.</p>
<h5><a name="2-3-2"></a>Loading and Executing a Dynamic Dialog</h5>
-<!-- index Dynamic Dialogs!Loading and Executing --><!-- index Dialogs!Dynamic --><!-- index Forms!Forward declarations --><!-- index Forward declarations --><!-- index Includes --><p>We'll now add the code to invoke the credit dialog. Before we can do this we need to add the widget factory's header file to the form. Click the Source tab in the Object Hierarchy. Right click Includes (in Implementation), then click <b>New</b>. Type in '<tt>&lt;tqwidgetfactory.h&gt;</tt>', then press <b>Enter</b>. Because we will need to access the spin box in the dynamic dialog we must add its header file. Right click Includes (in Implmentation), then click <b>New</b>. Type in '<tt>&lt;ntqspinbox.h&gt;</tt>', then press <b>Enter</b>.</p>
+<!-- index Dynamic Dialogs!Loading and Executing --><!-- index Dialogs!Dynamic --><!-- index Forms!Forward declarations --><!-- index Forward declarations --><!-- index Includes --><p>We'll now add the code to invoke the credit dialog. Before we can do this we need to add the widget factory's header file to the form. Click the Source tab in the Object Hierarchy. Right click Includes (in Implementation), then click <b>New</b>. Type in '<tt>&lt;tqwidgetfactory.h&gt;</tt>', then press <b>Enter</b>. Because we will need to access the spin box in the dynamic dialog we must add its header file. Right click Includes (in Implmentation), then click <b>New</b>. Type in '<tt>&lt;tqspinbox.h&gt;</tt>', then press <b>Enter</b>.</p>
<p>In our main form we created a slot called <tt>creditDialog()</tt>. We will implement this slot directly in <em>TQt Designer</em> and use it to load and execute the dynamic dialog. The code is taken from <tt>qt/tools/designer/examples/receiver1/mainform.ui.h</tt> which contains the C++ implementation of <tt>mainform.ui</tt>'s slots.</p>
<pre> void MainForm::creditDialog()
{
- <a href="ntqdialog.html">TQDialog</a> *creditForm = (TQDialog *)
+ <a href="tqdialog.html">TQDialog</a> *creditForm = (TQDialog *)
TQWidgetFactory::<a href="tqwidgetfactory.html#create">create</a>( "../credit/creditformbase.ui" );
// Set up the dynamic dialog here
- if ( creditForm-&gt;<a href="ntqdialog.html#exec">exec</a>() ) {
+ if ( creditForm-&gt;<a href="tqdialog.html#exec">exec</a>() ) {
// The user accepted, act accordingly
- <a href="ntqspinbox.html">TQSpinBox</a> *amount = (TQSpinBox *) creditForm-&gt;<a href="tqobject.html#child">child</a>( "amountSpinBox", "TQSpinBox" );
+ <a href="tqspinbox.html">TQSpinBox</a> *amount = (TQSpinBox *) creditForm-&gt;<a href="tqobject.html#child">child</a>( "amountSpinBox", "TQSpinBox" );
if ( amount )
- ratingTextLabel-&gt;setText( amount-&gt;<a href="ntqspinbox.html#text">text</a>() );
+ ratingTextLabel-&gt;setText( amount-&gt;<a href="tqspinbox.html#text">text</a>() );
}
delete creditForm;
}
</pre>
- <p>The<!-- index create() --> <tt>create()</tt> function is a static <a href="tqwidgetfactory.html">TQWidgetFactory</a> function. It loads the specified<!-- index .ui --> <tt>.ui</tt> file and returns a pointer to the toplevel <a href="tqwidget.html">TQWidget</a> created from the<!-- index .ui --> <tt>.ui</tt> file. We have cast the pointer to <a href="ntqdialog.html">TQDialog</a> since we know that the <tt>creditformbase.ui</tt> file defines a <a href="ntqdialog.html">TQDialog</a>. After creating the dialog we<!-- index exec() --> <tt>exec()</tt> it. If the user clicked <b>OK</b> the dialog returns Accepted and we enter the body of the <tt>if</tt> statement. We want to know the amount of credit that the user selected. We call the<!-- index child() --> <tt>child()</tt> function on the dialog passing it the name of the widget we're interested in. The<!-- index child() --> <tt>child()</tt> 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<!-- index child() --> <tt>child()</tt> 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.</p>
-<p>We used the<!-- index child() --> <tt>child()</tt> 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<!-- index child() --> <tt>child()</tt> with a null widget name and a classname, e.g. <tt>child(0,"TQPushButton")</tt>. This will return a pointer to the first <a href="ntqpushbutton.html">TQPushButton</a> 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<!-- index TQObject::queryList() --> <tt>TQObject::queryList()</tt> function, passing it the name of the class. It returns a <a href="tqobjectlist.html">TQObjectList</a> pointer which points to every object in the dialog that is derived from the given class. See the online <a href="http://doc.trolltech.com/tqobject.html">TQObject</a> documentation for further details.</p>
+ <p>The<!-- index create() --> <tt>create()</tt> function is a static <a href="tqwidgetfactory.html">TQWidgetFactory</a> function. It loads the specified<!-- index .ui --> <tt>.ui</tt> file and returns a pointer to the toplevel <a href="tqwidget.html">TQWidget</a> created from the<!-- index .ui --> <tt>.ui</tt> file. We have cast the pointer to <a href="tqdialog.html">TQDialog</a> since we know that the <tt>creditformbase.ui</tt> file defines a <a href="tqdialog.html">TQDialog</a>. After creating the dialog we<!-- index exec() --> <tt>exec()</tt> it. If the user clicked <b>OK</b> the dialog returns Accepted and we enter the body of the <tt>if</tt> statement. We want to know the amount of credit that the user selected. We call the<!-- index child() --> <tt>child()</tt> function on the dialog passing it the name of the widget we're interested in. The<!-- index child() --> <tt>child()</tt> 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<!-- index child() --> <tt>child()</tt> 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.</p>
+<p>We used the<!-- index child() --> <tt>child()</tt> 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<!-- index child() --> <tt>child()</tt> with a null widget name and a classname, e.g. <tt>child(0,"TQPushButton")</tt>. This will return a pointer to the first <a href="tqpushbutton.html">TQPushButton</a> 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<!-- index TQObject::queryList() --> <tt>TQObject::queryList()</tt> function, passing it the name of the class. It returns a <a href="tqobjectlist.html">TQObjectList</a> pointer which points to every object in the dialog that is derived from the given class. See the online <a href="http://doc.trolltech.com/tqobject.html">TQObject</a> documentation for further details.</p>
<h5><a name="2-3-3"></a>Implementing Slots for Dynamic Dialogs</h5>
<!-- index Signals and Slots!Dynamic Dialogs --><!-- index Dynamic Dialogs --><p>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 <tt>setAmount()</tt> slot. We can implement slots for dynamic dialogs by creating a <a href="tqobject.html">TQObject</a> subclass. We then create an instance of this subclass and pass a pointer to it to the<!-- index TQWidgetFactory::create() --> <tt>TQWidgetFactory::create()</tt> function which will connect the dynamic dialog's signals to the slots implemented in our subclass.</p>
<p>We need to create a <a href="tqobject.html">TQObject</a> subclass and change our <tt>creditDialog()</tt> to create an instance of our subclass that can be passed to the<!-- index TQWidgetFactory::create() --> <tt>TQWidgetFactory::create()</tt> function. Here is the modified <tt>creditDialog()</tt> function from the <tt>qt/tools/designer/examples/receiver2/mainform.ui.h</tt> file that contains the code for <tt>mainform.ui</tt>'s slots:</p>
<pre> void MainForm::creditDialog()
{
Receiver *receiver = new Receiver;
- <a href="ntqdialog.html">TQDialog</a> *creditForm = (TQDialog *)
+ <a href="tqdialog.html">TQDialog</a> *creditForm = (TQDialog *)
TQWidgetFactory::<a href="tqwidgetfactory.html#create">create</a>( "../credit/creditformbase.ui", receiver );
receiver-&gt;setParent( creditForm );
// Set up the dynamic dialog here
- if ( creditForm-&gt;<a href="ntqdialog.html#exec">exec</a>() ) {
+ if ( creditForm-&gt;<a href="tqdialog.html#exec">exec</a>() ) {
// The user accepted, act accordingly
- <a href="ntqspinbox.html">TQSpinBox</a> *amount = (TQSpinBox *) creditForm-&gt;<a href="tqobject.html#child">child</a>( "amountSpinBox", "TQSpinBox" );
+ <a href="tqspinbox.html">TQSpinBox</a> *amount = (TQSpinBox *) creditForm-&gt;<a href="tqobject.html#child">child</a>( "amountSpinBox", "TQSpinBox" );
if ( amount )
- ratingTextLabel-&gt;setText( amount-&gt;<a href="ntqspinbox.html#text">text</a>() );
+ ratingTextLabel-&gt;setText( amount-&gt;<a href="tqspinbox.html#text">text</a>() );
}
delete receiver;
delete creditForm;
}
</pre>
- <p>We create a new instance of our 'Receiver' subclass. (We'll write the code for this class shortly.) We then create the <a href="ntqdialog.html">TQDialog</a> using<!-- index TQWidgetFactory::create() --> <tt>TQWidgetFactory::create()</tt>. This call differs from our previous example because we pass in the subclass object so that the<!-- index create() --> <tt>create()</tt> function can set up the signals/slots connections automatically for us. Since our slot must access the widgets in the dynamic form we pass a pointer to the form to the receiver object through our <tt>setParent()</tt> function. The remainder of the function is the same as before except that we delete our receiver object.</p>
+ <p>We create a new instance of our 'Receiver' subclass. (We'll write the code for this class shortly.) We then create the <a href="tqdialog.html">TQDialog</a> using<!-- index TQWidgetFactory::create() --> <tt>TQWidgetFactory::create()</tt>. This call differs from our previous example because we pass in the subclass object so that the<!-- index create() --> <tt>create()</tt> function can set up the signals/slots connections automatically for us. Since our slot must access the widgets in the dynamic form we pass a pointer to the form to the receiver object through our <tt>setParent()</tt> function. The remainder of the function is the same as before except that we delete our receiver object.</p>
<p>Since we are using the 'Receiver' subclass in our main form we must include its header file. In <em>Object Explorer</em>'s Members tab, right click Includes (in Implmentation), then click <b>New</b>. Type in '<tt>receiver.h</tt>', then press <b>Enter</b>.</p>
<!-- index Dynamic Dialogs --><p>We'll now look at the implementation of our 'Receiver' subclass. The code is taken from <tt>qt/tools/designer/examples/receiver2/receiver.h</tt> and the corresponding <tt>receiver.cpp</tt> file. We'll start with the header file.</p>
<pre>#include &lt;<a href="tqobject-h.html">tqobject.h</a>&gt;
-#include &lt;<a href="qdialog-h.html">ntqdialog.h</a>&gt;
+#include &lt;<a href="tqdialog-h.html">tqdialog.h</a>&gt;
class Receiver : public <a href="tqobject.html">TQObject</a>
{
TQ_OBJECT
public:
- void setParent( <a href="ntqdialog.html">TQDialog</a> *parent );
+ void setParent( <a href="tqdialog.html">TQDialog</a> *parent );
public slots:
void setAmount();
private:
- <a href="ntqdialog.html">TQDialog</a> *p;
+ <a href="tqdialog.html">TQDialog</a> *p;
};
</pre>
-<!-- index Macros!TQ_OBJECT --><!-- index TQ_OBJECT!Macros --><p>Our class must be a <a href="tqobject.html">TQObject</a> subclass and because we're using signals and slots it must include the <tt>TQ_OBJECT</tt> macro. We declare a function and the <tt>setAmount()</tt> slot that we wish to implement as well as a private <a href="ntqdialog.html">TQDialog</a> pointer.</p>
+<!-- index Macros!TQ_OBJECT --><!-- index TQ_OBJECT!Macros --><p>Our class must be a <a href="tqobject.html">TQObject</a> subclass and because we're using signals and slots it must include the <tt>TQ_OBJECT</tt> macro. We declare a function and the <tt>setAmount()</tt> slot that we wish to implement as well as a private <a href="tqdialog.html">TQDialog</a> pointer.</p>
<p>The implementation requires the header files of the classes it uses:</p>
-<pre> #include &lt;<a href="qradiobutton-h.html">ntqradiobutton.h</a>&gt;
- #include &lt;<a href="qspinbox-h.html">ntqspinbox.h</a>&gt;
+<pre> #include &lt;<a href="tqradiobutton-h.html">tqradiobutton.h</a>&gt;
+ #include &lt;<a href="tqspinbox-h.html">tqspinbox.h</a>&gt;
#include "receiver.h"
</pre>
<p>We'll discuss the implementation of each function in <tt>receiver.cpp</tt> separately.</p>
-<pre> void Receiver::setParent( <a href="ntqdialog.html">TQDialog</a> *parent )
+<pre> void Receiver::setParent( <a href="tqdialog.html">TQDialog</a> *parent )
{
p = parent;
setAmount();
@@ -275,22 +275,22 @@ private:
<p>The <tt>setParent()</tt> function assigns a pointer to the dynamic dialog to our private pointer. We could not do this in a constructor call because we have to construct our Receiver object before we call<!-- index TQWidgetFactory::create() --> <tt>TQWidgetFactory::create()</tt>, since we must pass the Receiver object to the<!-- index create() --> <tt>create()</tt> function. Once we've called<!-- index create() --> <tt>create()</tt> we then have a pointer to the dynamic dialog which we can then pass via <tt>setParent()</tt> to our Receiver class. In the subclass version of this example we called <tt>setAmount()</tt> in the constructor; but we cannot do that here because the implementation of <tt>setAmount()</tt> depends on knowledge of the dynamic dialog which is not available at construction time. Because of this we call <tt>setAmount()</tt> in the <tt>setParent()</tt> function.</p>
<pre> void Receiver::setAmount()
{
- <a href="ntqspinbox.html">TQSpinBox</a> *amount =
+ <a href="tqspinbox.html">TQSpinBox</a> *amount =
(TQSpinBox *) p-&gt;child( "amountSpinBox", "TQSpinBox" );
- <a href="ntqradiobutton.html">TQRadioButton</a> *radio =
+ <a href="tqradiobutton.html">TQRadioButton</a> *radio =
(TQRadioButton *) p-&gt;child( "stdRadioButton", "TQRadioButton" );
- if ( radio &amp;&amp; radio-&gt;<a href="ntqradiobutton.html#isChecked">isChecked</a>() ) {
+ if ( radio &amp;&amp; radio-&gt;<a href="tqradiobutton.html#isChecked">isChecked</a>() ) {
if ( amount )
- amount-&gt;<a href="ntqspinbox.html#setValue">setValue</a>( amount-&gt;<a href="ntqspinbox.html#maxValue">maxValue</a>() / 2 );
+ amount-&gt;<a href="tqspinbox.html#setValue">setValue</a>( amount-&gt;<a href="tqspinbox.html#maxValue">maxValue</a>() / 2 );
return;
}
radio =
(TQRadioButton *) p-&gt;child( "noneRadioButton", "TQRadioButton" );
- if ( radio &amp;&amp; radio-&gt;<a href="ntqradiobutton.html#isChecked">isChecked</a>() )
+ if ( radio &amp;&amp; radio-&gt;<a href="tqradiobutton.html#isChecked">isChecked</a>() )
if ( amount )
- amount-&gt;<a href="ntqspinbox.html#setValue">setValue</a>( amount-&gt;<a href="ntqspinbox.html#minValue">minValue</a>() );
+ amount-&gt;<a href="tqspinbox.html#setValue">setValue</a>( amount-&gt;<a href="tqspinbox.html#minValue">minValue</a>() );
}
</pre>
<p>Since we may be updating the amount spin box we need to get a pointer to it. We call<!-- index child() --> <tt>child()</tt> on the pointer <tt>p</tt> which points to the dynamic dialog assigned in the <tt>setParent()</tt> call. We cast the resulting pointer to the correct type so that we can call any functions relevant to that type. In the example we call<!-- index child() --> <tt>child()</tt> to get a pointer to the amount spin box, and then call<!-- index child() --> <tt>child()</tt> again to get a pointer to the 'stdRadioButton'. If we get a pointer to the radio button and the button is checked we set the amount providing we have a pointer to the amount spin box. If this radio button was checked we're finished so we return. If the 'stdRadioButton' isn't checked we get a pointer to the 'noneRadioButton' and set the amount if this button is checked. We do nothing if the 'specialRadioButton' is checked because the user is free to enter a value of their choice.</p>