• 9609阅读
  • 3回复

[提问]关于QWizard和QWizardPage ,页与页之间传递数据 [复制链接]

上一主题 下一主题
离线frainbbs
 
只看楼主 倒序阅读 楼主  发表于: 2011-05-08
一个典型的向导程序包含一个QWizard对象和一或多个赋予ID的QWizardPage对象, 这样可以实现页面间的切换。(QT4.3白皮书)。
为了说清楚我的问题,引用 http://dev.firnow.com/course/3_program/c/c_js/20100710/396018.html 这个网页上的向导页例子。
我的问题是:在第一页设置一个QPushButton 和一个QLineEdit,在QLineEdit里面输入一个数字,不如实数100.0,点击下一步按钮,出现第二个页面,我想让第二个页面里设置的QLineEdit自动显示第一页输入的100.0。
请大家帮忙看一下,谢谢



离线dbzhang800

只看该作者 1楼 发表于: 2011-05-08
QWizard的manual有详细的介绍

题外:注意看
QWizardPage::registerField
离线roywillow

只看该作者 2楼 发表于: 2011-05-08
楼上题外应该是正解
专业维修核潜艇,回收二手航母、二手航天飞机,大修核反应堆,拆洗导弹发动机更换机油,无人侦察机手动挡改自动,航天飞机保养换三滤,飞碟外太空年检 ,各型号导弹加装迎宾踏板,高空作业擦洗卫星表面除尘、打蜡及抛光,东风全系列巡航导弹。并提供原子对撞机。量大从优,有正规发票。
离线frainbbs
只看该作者 3楼 发表于: 2011-05-08
详细说明:
Registering and Using Fields
In many wizards, the contents of a page may affect the default values of the fields of a later page. To make it easy to communicate between pages, QWizard supports a "field" mechanism that allows you to register a field (e.g., a QLineEdit) on a page and to access its value from any page. It is also possible to specify mandatory fields (i.e., fields that must be filled before the user can advance to the next page).

To register a field, call QWizardPage::registerField() field. For example:

ClassInfoPage::ClassInfoPage(QWidget *parent)
     : QWizardPage(parent)
{
     ...
     classNameLabel = new QLabel(tr("&Class name:"));
     classNameLineEdit = new QLineEdit;
     classNameLabel->setBuddy(classNameLineEdit);

     baseClassLabel = new QLabel(tr("B&ase class:"));
     baseClassLineEdit = new QLineEdit;
     baseClassLabel->setBuddy(baseClassLineEdit);

     qobjectMacroCheckBox = new QCheckBox(tr("Generate Q_OBJECT &macro"));

     registerField("className*", classNameLineEdit);
     registerField("baseClass", baseClassLineEdit);
     registerField("qobjectMacro", qobjectMacroCheckBox);
     ...
}

The above code registers three fields, className, baseClass, and qobjectMacro, which are associated with three child widgets. The asterisk (*) next to className denotes a mandatory field.

The fields of any page are accessible from any other page. For example:

void OutputFilesPage::initializePage()
{
     QString className = field("className").toString();
     headerLineEdit->setText(className.toLower() + ".h");
     implementationLineEdit->setText(className.toLower() + ".cpp");
     outputDirLineEdit->setText(QDir::convertSeparators(QDir::tempPath()));
}

具体看这个网页,QT4.4  http://web.mit.edu/wwinnie/MacData/afs/athena/software/qt-dynamic/www/qwizard.html

如果还看不懂,那就去找 Qt Wxamples and Demos -> Dialogs -> Class Wizard
这个例子中,在第一页输入的信息X,在第二页里面显示了。
快速回复
限100 字节
 
上一个 下一个