///client.hсlass Client : public QDialog { Q_OBJECT public: Client(QWidget *parent = 0);... private: QPushButton *quitButton; QDialogButtonBox *buttonBox;... };///!!!client.cppClient::Client(QWidget *parent) : QDialog(parent) { quitButton = new QPushButton(tr("Quit")); buttonBox = new QDialogButtonBox; buttonBox->addButton(quitButton, QDialogButtonBox::RejectRole); connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));.... QGridLayout *mainLayout = new QGridLayout; mainLayout->addWidget(buttonBox, ....); setLayout(mainLayout);.... }
///client.h[code]lass Client : public QDialog { Q_OBJECT public: Client(QWidget *parent = 0);... };///!!!client.cppClient::Client(QWidget *parent) : QDialog(parent) { quitButton = new QPushButton(tr("Quit")); QPushButton *buttonBox = new QDialogButtonBox; ButtonBox *buttonBox->addButton(quitButton, QDialogButtonBox::RejectRole); connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));.... QGridLayout *mainLayout = new QGridLayout; mainLayout->addWidget(buttonBox, ....); setLayout(mainLayout);.... }
int main(int argc, char *argv[]){Application app(argc, argv);Qlabel *label = new QLabel ("Hellow Qt!");label->show();return app.exec();
quitButton = new QPushButton(tr("Quit"));
C++ (Qt)#include <QtGui>#include "test.h" Test::Test(QWidget *parent) : QDialog(parent){ //QVBoxLayout *vbl = new QVBoxLayout(this); //vbl->addWidget(&m_label); m_label.setText("hello"); m_label.show();}
C++ (Qt)Test::Test(QWidget *parent) : QDialog(parent){ QVBoxLayout *vbl = new QVBoxLayout(this); m_label.setText("hello"); vbl->addWidget(&m_label);}
C++ (Qt)Test::Test(QWidget *parent) : QDialog(parent){ m_label.setParent(this); m_label.setText("hello");}