C++ (Qt)#include "click.h" MyDialog::MyDialog(): QDialog() { QGridLayout *layout = new QGridLayout(this); m_btn1 = new QPushButton(tr("BTN"), this); connect(m_btn1, SIGNAL(clicked()), this, SLOT(onClick())); layout->addWidget(m_btn1, 0, 0); QLabel *label = new QLabel; label->setText("label"); layout->addWidget(label, 0, 1); setLayout(layout);} void MyDialog::onClick() { label->setText("text"); //zdes ne rabotaet ((} int main(int argc, char *argv[]) { QApplication app(argc, argv); QTextCodec *codec = QTextCodec::codecForName("CP1251"); QTextCodec::setCodecForTr(codec); MyDialog dlg; dlg.show(); return app.exec();}
C++ (Qt)QLabel *label = new QLabel;
C++ (Qt)label = new QLabel;
C++ (Qt)class MyDialog : .....{....private: QLabel *m_label;}; MyDialog::MyDialog(): QDialog() {..... m_label = new QLabel;.....} void MyDialog::onClick() { m_label->setText("text"); }
C++ (Qt)#include <QtGui> void onClick(); int main(int argc, char *argv[]){ QApplication app(argc, argv); QWidget win; QGridLayout* layout = new QGridLayout(&win); QLabel *label = new QLabel; QPushButton *m_btn1 = new QPushButton("start", &win); QObject::connect(m_btn1, SIGNAL(clicked()), &win, SLOT(onClick())); layout->addWidget(m_btn1, 0, 0); label->setText("label"); layout->addWidget(label, 1, 0); win.setLayout(layout); win.show(); return app.exec();} void onClick() { label->setText("text"); }