#include <QtGui/QApplication>#include <QPushButton>#include <QLineEdit>#include <QLabel>#include <QTextCodec>int main(int argc, char *argv[]){ QApplication a(argc, argv); QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8")); QWidget *window = new QWidget(); window->setWindowTitle("Пробное приложение :)"); window->resize(320, 240); window->show(); QPushButton *button = new QPushButton("Кнопка", window); button->move(10, 10); button->show(); QLineEdit *ledit = new QLineEdit("Новая надпись", window); ledit->move(10, 50); ledit->show(); QLabel *mylabel = new QLabel("Надпись", window); mylabel->move(10, 90); mylabel->show(); return a.exec();}
C++ (Qt)#include <QtGui/QApplication>#include <QPushButton>#include <QLineEdit>#include <QLabel>#include <QTextCodec> int main(int argc, char *argv[]){ QApplication a(argc, argv); QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8")); QWidget *window = new QWidget(); window->setWindowTitle("Пробное приложение :)"); window->resize(320, 240); window->show(); QPushButton *button = new QPushButton("Кнопка", window); button->move(10, 10); button->show(); QLineEdit *ledit = new QLineEdit("Новая надпись", window); ledit->move(10, 50); ledit->show(); QLabel *mylabel = new QLabel("Надпись", window); mylabel->move(10, 90); mylabel->show(); QObject::connect( ledit, SIGNAL( textChanged( const QString & ) ), mylabel, SLOT( setText( const QString & ) ) ); return a.exec();}
#ifndef WIDGET_H#define WIDGET_H#include <QtGui/QWidget>namespace Ui{ class Widget;}class Widget : public QWidget{ Q_OBJECTpublic: Widget(QWidget *parent = 0); ~Widget(); signals: void nazvat(); private slots: void nazhali();private: Ui::Widget *ui;};#endif // WIDGET_H
#include "widget.h"#include "ui_widget.h"Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget){ ui->setupUi(this);}void Widget::nazhali(){ emit nazvat();}Widget::~Widget(){ delete ui;}
C++ (Qt)#ifndef WIDGET_H#define WIDGET_H #include <QWidget> class QPushButton;class QLineEdit;class QLabel; class Widget : public QWidget{ Q_OBJECT public: Widget(QWidget *parent = 0); private slots: void nazhali(); private: QPushButton *button; QLineEdit *ledit; QLabel *mylabel}; #endif // WIDGET_H
C++ (Qt)#include "widget.h"#include <QPushButton>#include <QLineEdit>#include <QLabel>#include <QLayout> Widget::Widget( QWidget *parent ) : QWidget( parent ){ QVBoxLayout *layout = new QVBoxLayout( this ); button = new QPushButton("Кнопка", window); layout->addWidget( button ); connect( button, SIGNAL( clicked() ), SLOT( nazhali() ) ); ledit = new QLineEdit("Новая надпись", window); layout->addWidget( ledit ); mylabel = new QLabel("Надпись", window); layout->addWidget( mylabel );} void Widget::nazhali(){ mylabel->setText( ledit->text() );}
C++ (Qt)#ifndef WIDGET_H#define WIDGET_H #include <QtGui/QWidget> namespace Ui{ class Widget;} class Widget : public QWidget{ Q_OBJECT public: Widget(QWidget *parent = 0); ~Widget(); private slots: void nazhali(); private: Ui::Widget *ui;}; #endif // WIDGET_H
C++ (Qt)#include "widget.h"#include "ui_widget.h" Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget){ ui->setupUi(this); connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(nashali()));} void Widget::nazhali(){ ui->label->setText(ui->lineEdit->text());} Widget::~Widget(){ delete ui;}