在QT3.*文档中,我读到Subclassing and Dynamic Dialogs这一节的时候,看代码没有看懂。
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 QObject subclass. We then create an instance of this subclass and pass a pointer to it to the QWidgetFactory::create() function which will connect the dynamic dialog's signals to the slots implemented in our subclass.
We need to create a QObject subclass and change our creditDialog() to create an instance of our subclass that can be passed to the QWidgetFactory::create() function. Here is the modified creditDialog() function from the qt/tools/designer/examples/receiver2/mainform.ui.h file that contains the code for mainform.ui's slots:
void MainForm::creditDialog()
{
Receiver *receiver = new Receiver;
QDialog *creditForm = (QDialog *)
QWidgetFactory::create( "../credit/creditformbase.ui", receiver );
receiver->setParent( creditForm );
// Set up the dynamic dialog here
if ( creditForm->exec() ) {
// The user accepted, act accordingly
QSpinBox *amount = (QSpinBox *) creditForm->child( "amountSpinBox", "QSpinBox" );
if ( amount )
ratingTextLabel->setText( amount->text() );
}
delete receiver;
delete creditForm;
}
这个receiver类在这里起到的作用是什么啊?
上面写到的是:connect the dynamic dialog's signals to the slots implemented in our subclass
create函数返回了一个dialog指针给creditForm的意思,就是把这个create的窗口的操作权交给creditForm咯?
那receiver->setParent( creditForm );这一句又做何用途呢?
[ 此贴被XChinux在2006-04-18 16:17重新编辑 ]