我用designer(QT3)创建了两个dialog,分别为form1,form2,分别保存为form.ui和form2.ui。form1上有button1,form2上有button2和textLabel1。我想点击button1,弹出form2,然后点击button2 ,textLabel1显示“hello,qt!”。
button1连接create1()槽。button2连接setLabel().都设置为modalless。
在form1.ui.h中有:
Form1::create1()
{QDialog *dialog=(QDialog *)QWidgetFactory::create("form2.ui");
if(dialog->exec())
{qDebug("enter exec");
/*QPushButton *pB1=(QPushButton *)dialog->child("pB1","QPushButton");*/
}
delete dialog;
}
问题1:if语句什么时候才能进去?
在form2.ui.h中
Form2::setLabel()
{ qDebug("enter setLabel");
textLabel1->setText("hello,qt!");
}
[size=3]问题2:运行之后发现,form2弹出,点击button2没有反映,即没有进入setLabel槽。当调用create1函数时,form2弹出来,但没有调用form2的构造函数(我qDebug跟踪的)。是不是QWidgetFactory::create函数的原因?它只是读出了ui文件,而实际上内存中并没有构建form2窗体?
问题3 :如果我想实现上面的功能,该怎么做?