- C/C++ code
#include<QtGui>class MyDlg : public QDialog{public: MyDlg(const QString &);};MyDlg::MyDlg(const QString &a){ QLabel *text=new QLabel(a); QPushButton *okbutton=new QPushButton(tr("Ok")); QPushButton *cancelbutton=new QPushButton(tr("Cancel")); QHBoxLayout *buttonlayout=new QHBoxLayout; buttonlayout->addWidget(okbutton); buttonlayout->addWidget(cancelbutton); QVBoxLayout *vboxlayout=new QVBoxLayout; vboxlayout->addWidget(text); vboxlayout->addLayout(buttonlayout); setLayout(vboxlayout);}int main(int argc,char *argv[]){ QApplication app(argc,argv); bool ok; QFont font = QFontDialog::getFont(&ok, QFont("Times", 12)); if (ok) { MyDlg choose(QObject::tr("You have chosen a font")); choose.show(); } else { MyDlg choose(QObject::tr("default font")); choose.show(); } return app.exec();}
各位大神看一下吧,刚刚学Qt,自己动手设计的小程序,为什么运行的时候choose对话框没有显示出来啊。刚开始学Qt,各种不懂啊
------解决方案--------------------
离开if语句,MyDlg对象就销毁了