diff --git a/day11/qtdemo1/main.cpp b/day11/qtdemo1/main.cpp new file mode 100755 index 0000000..c3efeb4 --- /dev/null +++ b/day11/qtdemo1/main.cpp @@ -0,0 +1,11 @@ +#include "widget.h" + +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + Widget w; + w.show(); + return a.exec(); +} diff --git a/day11/qtdemo1/qtdemo1.pro b/day11/qtdemo1/qtdemo1.pro new file mode 100755 index 0000000..f73b0da --- /dev/null +++ b/day11/qtdemo1/qtdemo1.pro @@ -0,0 +1,33 @@ +QT += core gui + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +CONFIG += c++11 + +# The following define makes your compiler emit warnings if you use +# any Qt feature that has been marked deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +# You can also make your code fail to compile if it uses deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +SOURCES += \ + main.cpp \ + student.cpp \ + teacher.cpp \ + widget.cpp + +HEADERS += \ + student.h \ + teacher.h \ + widget.h + +TARGET = moneyorno +# Default rules for deployment. +qnx: target.path = /tmp/$${TARGET}/bin +else: unix:!android: target.path = /opt/$${TARGET}/bin +!isEmpty(target.path): INSTALLS += target diff --git a/day11/qtdemo1/student.cpp b/day11/qtdemo1/student.cpp new file mode 100755 index 0000000..5ff5e9e --- /dev/null +++ b/day11/qtdemo1/student.cpp @@ -0,0 +1,11 @@ +#include "student.h" + +Student::Student(QWidget *parent) : QWidget(parent) +{ + +} + +void Student::drink() +{ + qDebug() << "请老师吃冷饮" << endl; +} diff --git a/day11/qtdemo1/student.h b/day11/qtdemo1/student.h new file mode 100755 index 0000000..2dcfbaf --- /dev/null +++ b/day11/qtdemo1/student.h @@ -0,0 +1,20 @@ +#ifndef STUDENT_H +#define STUDENT_H + +#include +#include + +class Student : public QWidget +{ + Q_OBJECT +public: + explicit Student(QWidget *parent = nullptr); + +public slots: + void drink(); + +signals: + +}; + +#endif // STUDENT_H diff --git a/day11/qtdemo1/teacher.cpp b/day11/qtdemo1/teacher.cpp new file mode 100755 index 0000000..bb3676a --- /dev/null +++ b/day11/qtdemo1/teacher.cpp @@ -0,0 +1,6 @@ +#include "teacher.h" + +Teacher::Teacher(QWidget *parent) : QWidget(parent) +{ + +} diff --git a/day11/qtdemo1/teacher.h b/day11/qtdemo1/teacher.h new file mode 100755 index 0000000..10a1c28 --- /dev/null +++ b/day11/qtdemo1/teacher.h @@ -0,0 +1,17 @@ +#ifndef TEACHER_H +#define TEACHER_H + +#include + +class Teacher : public QWidget +{ + Q_OBJECT +public: + explicit Teacher(QWidget *parent = nullptr); + +signals: + void hot(); + +}; + +#endif // TEACHER_H diff --git a/day11/qtdemo1/widget.cpp b/day11/qtdemo1/widget.cpp new file mode 100755 index 0000000..376d76e --- /dev/null +++ b/day11/qtdemo1/widget.cpp @@ -0,0 +1,69 @@ +#include "widget.h" + +Widget::Widget(QWidget *parent) + : QWidget(parent) +{ + resize(500,300); + setWindowTitle("热了与冷饮"); + n=0; + + btn = new QPushButton("热了",this); + btn->setFixedSize(100,50); + btn->move(100,100); + + btn2 = new QPushButton("没钱了",this); + btn2->setFixedSize(100,50); + btn2->move(100,200); + + lable1 = new QLabel("显示",this); + lable1->setFixedSize(200,50); + lable1->move(250,100); + + lable2 = new QLabel("请客次数: ",this); + lable2->setFixedSize(200,50); + lable2->move(250,200); + + + + + t1 = new Teacher(); + s1 = new Student(); + + connect(t1,&Teacher::hot,s1,&Student::drink); + connect(btn,&QPushButton::clicked,this,&Widget::handleHot); + connect(btn2,&QPushButton::clicked,this,&Widget::noMoney); + + + emit t1->hot(); +} + +void Widget::handleHot() +{ + emit t1->hot(); + Widget::print(); +} + +void Widget::print() +{ + + n++; + if(n>0){ + if(n%2==0) + lable1->setText("请老师吃巧乐兹"); + else + lable1->setText("请老师吃老冰棍"); + lable2->setText("请客次数: "+QString::number(n)); + } +} + +void Widget::noMoney() +{ + n=0; + lable1->setText("请老师喝西北风"); + lable2->setText("请客次数: "+QString::number(n)); +} + +Widget::~Widget() +{ +} + diff --git a/day11/qtdemo1/widget.h b/day11/qtdemo1/widget.h new file mode 100755 index 0000000..d0c25eb --- /dev/null +++ b/day11/qtdemo1/widget.h @@ -0,0 +1,32 @@ +#ifndef WIDGET_H +#define WIDGET_H + +#include +#include +#include +#include "teacher.h" +#include "student.h" + +class Widget : public QWidget +{ + Q_OBJECT + +private: + Teacher *t1; + Student *s1; + int n; + +private: + QPushButton *btn,*btn2; + QLabel *lable1,*lable2; + +public slots: + void handleHot(); + void print(); + void noMoney(); + +public: + Widget(QWidget *parent = nullptr); + ~Widget(); +}; +#endif // WIDGET_H