delete ok_label; delete ok_button; delete cancel_label; delete cancel_button; delete warning_label; delete button_layout; delete central_layout; emit bye();//посылает сигнал на выключение основному приложению close();
ok_button = new QPushButton; cancel_button = new QPushButton; ok_label = new QLabel(ok_button); cancel_label = new QLabel(cancel_button); warning_label = new QLabel; central_layout = new QVBoxLayout; button_layout = new QHBoxLayout;
central_layout->addWidget(warning_label,Qt::AlignAbsolute); central_layout->addStretch(); central_layout->addLayout(button_layout,Qt::AlignAbsolute); button_layout->addWidget(ok_button,Qt::AlignAbsolute); button_layout->addStretch(); button_layout->addWidget(cancel_button,Qt::AlignAbsolute); setLayout(central_layout);
QFile file; QTextStream stream(&file); file.setFileName("config/object_text_content/age_warning"); if(!file.open(QIODevice::ReadOnly|QIODevice::Text)) return; warning_label->setText(stream.readAll()); stream.flush(); file.close(); file.setFileName("config/object_text_content/age_warning_button"); if(!file.open(QIODevice::ReadOnly|QIODevice::Text)) return; ok_label->setText(stream.readLine()); cancel_label->setText(stream.readLine()); stream.flush(); file.close();
// удаление нестандартных лейбловdelete nestandartLabel;emit bye();close();
#include "widget.h"Widget::Widget(QWidget *parent) : QWidget(parent){ html_label = new QLabel(this); exit_button = new QPushButton(this); main_layout = new QVBoxLayout(this); main_layout->addWidget(html_label); main_layout->addStretch(); main_layout->addWidget(exit_button); setLayout(main_layout); exit_button->setText("goodbye"); html_label->setText("<p><img src=img/1.JPG width=1024 height=768 alt=test><p>test img</p></p><p>THIS IS TEST</p>"); connect(exit_button,SIGNAL(clicked()),SLOT(goodbye()));}Widget::~Widget(){}void Widget::goodbye(){ delete html_label;//теоретически это избыточно и если верить Шелле все само за сабой чиститься, но всеже delete exit_button; delete main_layout; emit bye(); close();}
#ifndef WIDGET_H#define WIDGET_H#include <QtGui/QWidget>#include <QPushButton>#include <QLabel>#include <QVBoxLayout>class Widget : public QWidget{ Q_OBJECTpublic: Widget(QWidget *parent = 0); ~Widget(); QLabel *html_label; QPushButton *exit_button; QVBoxLayout *main_layout;private slots: void goodbye();signals: void bye();};#endif // WIDGET_H
#include <QtGui/QApplication>#include "widget.h"int main(int argc, char *argv[]){ QApplication *a=new QApplication(argc, argv); Widget *w=new Widget; w->show(); QObject::connect(w,SIGNAL(bye()),a,SLOT(quit())); return a->exec();}
#include "age_enquirer.h"age_enquirer::age_enquirer(QWidget *parent) : QWidget(parent){ ok_button = new QPushButton(this); cancel_button = new QPushButton(this); warning_text = new QLabel(this); ok_label = new QLabel(ok_button); cancel_label = new QLabel(cancel_button); button_layout = new QHBoxLayout; main_layout = new QVBoxLayout(this); main_layout->addWidget(warning_text); main_layout->addStretch(); main_layout->addLayout(button_layout); button_layout->addWidget(ok_button); button_layout->addStretch(); button_layout->addWidget(cancel_button); setLayout(main_layout); setFixedSize(500,500); load_content(); connect(cancel_button,SIGNAL(clicked()),SLOT(goodbye()));}age_enquirer::~age_enquirer(){}void age_enquirer::load_content(){ QFile file; QTextStream stream(&file); file.setFileName("config/object_text_content/age_warning"); if(!file.open(QIODevice::ReadOnly|QIODevice::Text)) return; warning_text->setText(stream.readAll()); stream.flush(); file.close(); file.setFileName("config/object_text_content/age_warning_button"); if(!file.open(QIODevice::ReadOnly|QIODevice::Text)) return; //ok_label->setText(stream.readLine()); //cancel_label->setText(stream.readLine()); stream.flush(); file.close();}void age_enquirer::goodbye(){ delete ok_label; delete cancel_label; delete ok_button; delete cancel_button; delete button_layout; delete warning_text; delete main_layout; emit bye(); close();}
#ifndef AGE_ENQUIRER_H#define AGE_ENQUIRER_H#include <QtGui/QWidget>#include <QLabel>#include <QPushButton>#include <QVBoxLayout>#include <QHBoxLayout>#include <QFile>#include <QTextStream>class age_enquirer : public QWidget{ Q_OBJECTpublic: age_enquirer(QWidget *parent = 0); ~age_enquirer(); QLabel *warning_text; QLabel *ok_label; QLabel *cancel_label; QPushButton *ok_button; QPushButton *cancel_button; QVBoxLayout *main_layout; QHBoxLayout *button_layout;private: void load_content();private slots: void goodbye();signals: void bye();};#endif // AGE_ENQUIRER_H
#include <QtGui/QApplication>#include <QTextCodec>#include "age_enquirer.h"int main(int argc, char *argv[]){ QApplication *a = new QApplication(argc, argv); QTextCodec::setCodecForLocale(QTextCodec::codecForLocale()); age_enquirer *age= new age_enquirer; age->show(); QObject::connect(age,SIGNAL(bye()),a,SLOT(quit())); return a->exec();}