├── AutoRunSelf ├── AutoRunSelf.pro ├── AutoRunSelf.pro.user ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui ├── src.qrc └── test.ico ├── Clock ├── Clock.pro ├── Clock.pro.user ├── Clock.pro.user.4.8-pre1 ├── Clock.pro.user.c89dd91 ├── Clock.pro.user.cb5ce59 ├── back.jpg ├── main.cpp ├── widget.cpp ├── widget.h └── widget.ui ├── MD5 ├── MD5.pro ├── MD5.pro.user ├── MD5.pro.user.c89dd91 ├── Md5Check │ ├── md5check.cpp │ └── md5check.h ├── main.cpp ├── widget.cpp ├── widget.h └── widget.ui ├── NotePad ├── NotePad.pro ├── NotePad.pro.user ├── highlighter.cpp ├── highlighter.h ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui ├── src.qrc └── src │ ├── close.png │ ├── deroy.jpg │ ├── edit_all.png │ ├── edit_bing.png │ ├── edit_copy.png │ ├── edit_cut.png │ ├── edit_date.png │ ├── edit_del.png │ ├── edit_find.png │ ├── edit_find_n.png │ ├── edit_goto.png │ ├── edit_past.png │ ├── edit_replace.png │ ├── edit_undo.png │ ├── editcopy.png │ ├── editcut.png │ ├── editpaste.png │ ├── editredo.png │ ├── editundo.png │ ├── exportpdf.png │ ├── file_close.png │ ├── file_exit.png │ ├── file_new.png │ ├── file_open.png │ ├── file_print.png │ ├── file_pset.png │ ├── file_save.png │ ├── file_saveas.png │ ├── filenew.png │ ├── fileopen.png │ ├── fileprint.png │ ├── filesave.png │ ├── form_autoline.png │ ├── form_color.png │ ├── form_font.png │ ├── help.png │ ├── help_about.png │ ├── help_csdn.png │ ├── icon.png │ ├── textbold.png │ ├── textcenter.png │ ├── textitalic.png │ ├── textjustify.png │ ├── textleft.png │ ├── textright.png │ ├── textunder.png │ ├── view_status.png │ ├── view_zoom.png │ ├── zoomin.png │ └── zoomout.png ├── QRunnable_QThreadPoll ├── QRunnable_QThreadPoll.pro ├── QRunnable_QThreadPoll.pro.user ├── main.cpp ├── myrunable.cpp └── myrunable.h ├── QThread_Demo_console ├── QThread_Demo_console.pro ├── QThread_Demo_console.pro.user ├── main.cpp ├── mythread.cpp ├── mythread.h └── readme.txt ├── QThread_QMutex_Demo ├── QThread_QMutex_Demo.pro ├── QThread_QMutex_Demo.pro.user ├── main.cpp ├── mythread.cpp └── mythread.h ├── QThread_QWaitCondition_Demo ├── QThread_QWaitCondition_Demo.pro ├── QThread_QWaitCondition_Demo.pro.user └── main.cpp ├── Qt_Linguist _Demo ├── build-language_demo-Desktop_Qt_5_12_1_MinGW_64_bit-Debug │ ├── .qmake.stash │ ├── Makefile │ ├── Makefile.Debug │ ├── Makefile.Release │ ├── Translate_CN.qm │ ├── Translate_EN.qm │ ├── debug │ │ ├── language_demo.exe │ │ ├── main.o │ │ ├── mainwindow.o │ │ ├── moc_mainwindow.cpp │ │ ├── moc_mainwindow.o │ │ └── moc_predefs.h │ └── ui_mainwindow.h └── language │ ├── Translate_CN.qm │ ├── Translate_CN.ts │ ├── Translate_EN.qm │ ├── Translate_EN.ts │ ├── language_demo.pro │ ├── language_demo.pro.user │ ├── main.cpp │ ├── mainwindow.cpp │ ├── mainwindow.h │ └── mainwindow.ui ├── SrceenWidget ├── SrceenWidget.pro ├── SrceenWidget.pro.user ├── main.cpp ├── src.qrc ├── src │ ├── apple.ico │ └── screenshot.png ├── srceen.cpp ├── srceen.h ├── widget.cpp ├── widget.h └── widget.ui ├── ThreadDemo ├── ThreadDemo.pro ├── ThreadDemo.pro.user ├── ThreadDemo.pro.user.c89dd91 ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui ├── mythread.cpp ├── mythread.h ├── readme.txt ├── test.cpp └── test.h ├── readme.md ├── scrollArea-demo ├── Simpson.jpg ├── ToolBoxPow.cpp ├── ToolBoxPow.h ├── arrow_down_normal.png ├── arrow_right_normal.png ├── bianchenxuexijidi.jpg ├── blownbear.jpg ├── dog.jpg ├── duolaameng.jpg ├── haimianbob.jpg ├── icebear.jpg ├── main.cpp ├── panda.jpg ├── scrollArea-demo.pro ├── scrollArea-demo.pro.user ├── src.qrc ├── tom.jpg ├── widget.cpp ├── widget.h ├── widget.ui └── xiaoxin.jpg ├── tcp_Server ├── main.cpp ├── tcp_Server.pro ├── tcp_Server.pro.user ├── widget.cpp ├── widget.h └── widget.ui └── tcp_client ├── main.cpp ├── tcp_client.pro ├── tcp_client.pro.user ├── tcp_client.pro.user.c89dd91 ├── widget.cpp ├── widget.h └── widget.ui /AutoRunSelf/AutoRunSelf.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2020-07-26T21:32:29 4 | # 5 | #------------------------------------------------- 6 | 7 | QT += core gui 8 | 9 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 10 | 11 | TARGET = AutoRunSelf 12 | TEMPLATE = app 13 | 14 | # The following define makes your compiler emit warnings if you use 15 | # any feature of Qt which has been marked as deprecated (the exact warnings 16 | # depend on your compiler). Please consult the documentation of the 17 | # deprecated API in order to know how to port your code away from it. 18 | DEFINES += QT_DEPRECATED_WARNINGS 19 | 20 | # You can also make your code fail to compile if you use deprecated APIs. 21 | # In order to do so, uncomment the following line. 22 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 23 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 24 | 25 | CONFIG += c++11 26 | 27 | SOURCES += \ 28 | main.cpp \ 29 | mainwindow.cpp 30 | 31 | HEADERS += \ 32 | mainwindow.h 33 | 34 | FORMS += \ 35 | mainwindow.ui 36 | 37 | # Default rules for deployment. 38 | qnx: target.path = /tmp/$${TARGET}/bin 39 | else: unix:!android: target.path = /opt/$${TARGET}/bin 40 | !isEmpty(target.path): INSTALLS += target 41 | 42 | RESOURCES += \ 43 | src.qrc 44 | -------------------------------------------------------------------------------- /AutoRunSelf/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication a(argc, argv); 7 | MainWindow w; 8 | w.show(); 9 | 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /AutoRunSelf/mainwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include "ui_mainwindow.h" 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | //开机启动注册表 9 | #define AUTO_RUN "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run" 10 | 11 | MainWindow::MainWindow(QWidget *parent) : 12 | QMainWindow(parent), 13 | ui(new Ui::MainWindow) 14 | { 15 | ui->setupUi(this); 16 | /* 17 | * 18 | * 系统托盘 19 | * 20 | */ 21 | minimizeAction = new QAction(tr("最小化"), this); 22 | minimizeAction->setIcon(QIcon(":/test.ico")); //设置ico 23 | connect(minimizeAction, SIGNAL(triggered()), this, SLOT(hide())); 24 | 25 | maximizeAction = new QAction(tr("退出"), this); 26 | maximizeAction->setIcon(QIcon(":/test.ico")); 27 | connect(maximizeAction, SIGNAL(triggered()), this, SLOT(close())); 28 | 29 | trayIconMenu = new QMenu(this); 30 | trayIconMenu->addAction(minimizeAction); 31 | trayIconMenu->addAction(maximizeAction); 32 | trayIcon = new QSystemTrayIcon(this); 33 | /*将之前加载的菜单设置为系统托盘菜单*/ 34 | trayIcon->setContextMenu(trayIconMenu); 35 | /* 设置托盘显示的图标。 */ 36 | trayIcon->setIcon(QIcon(":/test.ico")); 37 | setWindowIcon(QIcon(":/test.ico")); 38 | /* 设置鼠标移动到托盘图标显示的文本。 */ 39 | trayIcon->setToolTip("提示"); 40 | trayIcon->show(); 41 | 42 | /* 43 | * 44 | * 系统设置 45 | * 46 | */ 47 | setting = new QButtonGroup(this); 48 | setting->addButton(ui->autoRunButton,0); 49 | setting->addButton(ui->setting_button,1); 50 | setting->setExclusive(false); //设置不互斥 51 | connect(setting, SIGNAL(buttonClicked(int)), this, SLOT(slot_CheckButton_checket(int))); 52 | read_ini(); 53 | } 54 | 55 | MainWindow::~MainWindow() 56 | { 57 | delete ui; 58 | } 59 | 60 | void MainWindow::slot_CheckButton_checket(int ButtonId) 61 | { 62 | /*group修改,写入配置文件*/ 63 | QCheckBox* temp = (QCheckBox*)setting->button(ButtonId); 64 | switch(ButtonId) 65 | { 66 | case 0: 67 | if(temp->isChecked()) 68 | { 69 | SetAutoRun(true); 70 | qDebug()<<"开启:开机自启"; 71 | } 72 | else { 73 | SetAutoRun(false); 74 | qDebug()<<"关闭:开机自启"; 75 | } 76 | break; 77 | case 1: 78 | qDebug()<<"其他设置"; 79 | break; 80 | } 81 | write_ini(); 82 | } 83 | 84 | void MainWindow::write_ini() 85 | { 86 | //打开配置文件 87 | QSettings *config = new QSettings("test.ini", QSettings::IniFormat); 88 | //设置编码方式 89 | config->setIniCodec(QTextCodec::codecForName("utf‐8")); 90 | //设置组group 91 | QString section=QString("setting/"); //一定要加/,否则读取会出问题 92 | config->beginGroup(section); //设置组 93 | config->setValue(QString("%1").arg(setting->button(0)->text()),QString("%1").arg(setting->button(0)->isChecked())); 94 | config->setValue(QString("%1").arg(setting->button(1)->text()),QString("%1").arg(setting->button(1)->isChecked())); 95 | config->endGroup(); 96 | delete config; 97 | } 98 | 99 | void MainWindow::read_ini() 100 | { 101 | int value; 102 | //打开配置文件 103 | QSettings *config = new QSettings("test.ini", QSettings::IniFormat); 104 | //设置编码方式 105 | config->setIniCodec(QTextCodec::codecForName("utf‐8")); 106 | //设置组group 107 | QString section=QString("setting/"); //一定要加/,否则读取会出问题 108 | 109 | value = config->value(section + QString("%1").arg(setting->button(0)->text())).toInt(); 110 | setting->button(0)->setChecked(value); 111 | 112 | value = config->value(section + QString("%1").arg(setting->button(1)->text())).toInt(); 113 | setting->button(1)->setChecked(value); 114 | 115 | delete config; 116 | } 117 | 118 | void MainWindow::SetAutoRun(bool isAutoRun) 119 | { 120 | QString strApplicationName = QApplication::applicationName(); //获取应用名称 121 | QSettings * settings = new QSettings(AUTO_RUN, QSettings::NativeFormat); 122 | 123 | if(isAutoRun) 124 | { 125 | QString strApplicationFilePath = QApplication::applicationFilePath(); //找到应用的目录 126 | settings->setValue(strApplicationName, strApplicationFilePath.replace("/", "\\"));//写入注册表 127 | } 128 | else 129 | settings->remove(strApplicationName); 130 | } 131 | 132 | -------------------------------------------------------------------------------- /AutoRunSelf/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | namespace Ui { 13 | class MainWindow; 14 | } 15 | 16 | class MainWindow : public QMainWindow 17 | { 18 | Q_OBJECT 19 | 20 | public: 21 | explicit MainWindow(QWidget *parent = nullptr); 22 | ~MainWindow(); 23 | private slots: 24 | void slot_CheckButton_checket(int); 25 | 26 | private: 27 | void write_ini(); 28 | void read_ini(); 29 | void SetAutoRun(bool isAutoRun);//是否开机启动 30 | private: 31 | Ui::MainWindow *ui; 32 | QSystemTrayIcon *trayIcon; 33 | QMenu *trayIconMenu; 34 | QAction *minimizeAction; 35 | QAction *maximizeAction; 36 | 37 | /*CheckBox*/ 38 | QButtonGroup* setting; 39 | }; 40 | 41 | #endif // MAINWINDOW_H 42 | -------------------------------------------------------------------------------- /AutoRunSelf/mainwindow.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 296 10 | 439 11 | 12 | 13 | 14 | MainWindow 15 | 16 | 17 | 18 | 19 | 20 | 10 21 | 20 22 | 151 23 | 141 24 | 25 | 26 | 27 | 设置 28 | 29 | 30 | 31 | 32 | 20 33 | 40 34 | 71 35 | 16 36 | 37 | 38 | 39 | 开机自启 40 | 41 | 42 | 43 | 44 | 45 | 20 46 | 80 47 | 71 48 | 16 49 | 50 | 51 | 52 | 其他设置 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 0 61 | 0 62 | 296 63 | 23 64 | 65 | 66 | 67 | 68 | 69 | TopToolBarArea 70 | 71 | 72 | false 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /AutoRunSelf/src.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | test.ico 4 | 5 | 6 | -------------------------------------------------------------------------------- /AutoRunSelf/test.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/AutoRunSelf/test.ico -------------------------------------------------------------------------------- /Clock/Clock.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2019-07-10T21:05:40 4 | # 5 | #------------------------------------------------- 6 | 7 | QT += core gui 8 | 9 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 10 | 11 | TARGET = Clock 12 | TEMPLATE = app 13 | 14 | # The following define makes your compiler emit warnings if you use 15 | # any feature of Qt which has been marked as deprecated (the exact warnings 16 | # depend on your compiler). Please consult the documentation of the 17 | # deprecated API in order to know how to port your code away from it. 18 | DEFINES += QT_DEPRECATED_WARNINGS 19 | 20 | # You can also make your code fail to compile if you use deprecated APIs. 21 | # In order to do so, uncomment the following line. 22 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 23 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 24 | 25 | 26 | SOURCES += \ 27 | main.cpp \ 28 | widget.cpp 29 | 30 | HEADERS += \ 31 | widget.h 32 | 33 | FORMS += \ 34 | widget.ui 35 | -------------------------------------------------------------------------------- /Clock/back.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/Clock/back.jpg -------------------------------------------------------------------------------- /Clock/main.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication a(argc, argv); 7 | Widget w; 8 | w.show(); 9 | 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /Clock/widget.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | #include "ui_widget.h" 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | Widget::Widget(QWidget *parent) : 11 | QWidget(parent), 12 | ui(new Ui::Widget) 13 | { 14 | ui->setupUi(this); 15 | this->setWindowTitle("数字时钟"); 16 | time = new QTimer(this); 17 | //每 1s 刷新屏幕 ,间接调用paintEvent事件 18 | connect(time, SIGNAL(timeout()), this, SLOT(update())); 19 | createRightPopActions(); 20 | init(); 21 | time->start(1000); 22 | } 23 | Widget::~Widget() 24 | { 25 | delete ui; 26 | } 27 | 28 | void Widget::paintEvent(QPaintEvent *event) 29 | { 30 | Q_UNUSED(event); 31 | 32 | QPainter back(this); 33 | back.drawPixmap(0,0,QPixmap("back.jpg")); 34 | QFont font; 35 | double rotate; //每次旋转角度 36 | QDate date = QDate::currentDate(); 37 | QTime time = QTime::currentTime(); 38 | QDateTime dateTime = QDateTime::currentDateTime(); 39 | 40 | /******字体设置******/ 41 | font.setPointSize(12); //字体大小 42 | font.setFamily("楷体"); //字体 43 | /******文字设置******/ 44 | back.setPen(Qt::white); //设置 字体颜色 45 | back.setFont(font); //设置 字体 46 | /******范围设置******/ 47 | back.setRenderHint(QPainter::Antialiasing); //防锯齿 48 | back.translate(this->width() / 2, this->height() / 2); //设置中心 49 | int side = qMin(width(), height()); //定义一个边界,保证是圆形的 50 | back.scale(side / 1200.0, side / 1200.0); 51 | 52 | //开始画图 53 | //back.begin(this); 54 | /**********年份**********/ 55 | back.drawText(QPoint(-50, 0), QString("二零一九年")); 56 | /**********月份**********/ 57 | back.rotate((1 - date.month()) * 30); 58 | for (int i = 0; i < 12; i++) 59 | { 60 | if ((i + 1) == date.month()) 61 | { 62 | back.drawText(QPoint(90, 0), strListDate[i]+QString("月")); 63 | back.rotate(30); 64 | continue; 65 | } 66 | back.drawText(QPoint(100, 0), strListDate[i]); 67 | back.rotate(30); 68 | } 69 | /**********日期**********/ 70 | rotate = 360.0 / MaxDate(date.month()); 71 | back.rotate((date.month() - 1) * 30); //将角度置零 72 | back.rotate((1 - date.day())*rotate); //调节使当前日期在x轴上 73 | 74 | for (int i = 0; i < (int)MaxDate(date.month()); i++) 75 | { 76 | if ((i + 1) == date.day()) 77 | { 78 | back.drawText(QPoint(150, 0), strListDate[i] + QString("号")); 79 | back.rotate(rotate); 80 | continue; 81 | } 82 | back.drawText(QPoint(150, 0), strListDate[i]); 83 | back.rotate(rotate); 84 | } 85 | /**********星期**********/ 86 | back.rotate((date.day() - 1)*rotate); //将角度置零 87 | QString tempStr = dateTime.toString().left(2); //找到周 * 88 | back.rotate(-Week(tempStr, strListWeek)*360.0 / 7.0); //逆时针旋转 89 | for (int i = 0; i < 7; i++) 90 | { 91 | back.drawText(QPoint(210, 0), strListWeek[i]); 92 | back.rotate(360.0/7.0); 93 | } 94 | /**********状态**********/ 95 | double initRotate; //状态 96 | back.rotate(Week(tempStr, strListWeek)*360.0 / 7.0); //将角度置零 97 | if (time.hour() >= 6 && time.hour() < 12) initRotate = 0; 98 | if (time.hour() >= 12 && time.hour() < 14) initRotate = -1; 99 | if (time.hour() >= 14 && time.hour() < 19) initRotate = -2; 100 | if (time.hour() >= 19 || time.hour() < 6) initRotate = -3; 101 | back.rotate(initRotate * 90); //初始化状态 102 | for (int i = 0; i < 4; i++) 103 | { 104 | back.drawText(QPoint(280, 0), strListState[i]); 105 | back.rotate(90); 106 | } 107 | /**********小时**********/ 108 | back.rotate(-initRotate * 90); //将角度置零 109 | back.rotate((1-time.hour()) * 30); //初始化状态 110 | for (int i = 0; i < 12; i++) 111 | { 112 | if (time.hour() == (i + 1) || (time.hour() - 12) == (i + 1)) 113 | { 114 | back.drawText(QPoint(390, 0), strListDate[i] + QString("点")); 115 | back.rotate(30); 116 | continue; 117 | } 118 | back.drawText(QPoint(390, 0), strListDate[i]); 119 | back.rotate(30); 120 | } 121 | /**********分钟**********/ 122 | back.rotate((-1 + time.hour()) * 30); //返回旋转前的角度 123 | back.rotate((1 - time.minute()) * 6); //初始化状态 124 | for (int i = 0; i < 60; i++) 125 | { 126 | if (time.minute() == (i + 1)) 127 | { 128 | back.drawText(QPoint(450, 0), strListDate[i]+QString("分")); 129 | back.rotate(6); 130 | continue; 131 | } 132 | back.drawText(QPoint(450, 0), strListDate[i]); 133 | back.rotate(6); 134 | } 135 | /**********秒钟**********/ 136 | back.rotate((time.minute() - 1) * 6); //返回旋转前的角度 137 | back.rotate((1 - time.second()) * 6); //初始化状态 138 | for (int i = 0; i < 60; i++) 139 | { 140 | if (time.second() == (i + 1)) 141 | { 142 | back.drawText(QPoint(530, 0), strListDate[i] + QString("秒")); 143 | back.rotate(6); 144 | continue; 145 | } 146 | back.drawText(QPoint(530, 0), strListDate[i]); 147 | back.rotate(6); 148 | } 149 | 150 | //back.end(); 151 | } 152 | 153 | void Widget::mousePressEvent(QMouseEvent *event) 154 | { 155 | Q_UNUSED(event); 156 | } 157 | 158 | void Widget::keyPressEvent(QKeyEvent *event) 159 | { 160 | Q_UNUSED(event); 161 | } 162 | 163 | void Widget::mouseDoubleClickEvent(QMouseEvent *event) 164 | { 165 | Q_UNUSED(event); 166 | if (this->isFullScreen()) 167 | { 168 | this->showNormal(); 169 | } 170 | else 171 | { 172 | this->showFullScreen(); 173 | } 174 | } 175 | 176 | void Widget::contextMenuEvent(QContextMenuEvent *event) 177 | { 178 | Q_UNUSED(event); 179 | popMenu->clear(); 180 | popMenu->addAction(adjustTimeAction); 181 | popMenu->addAction(adjustDateAction); 182 | popMenu->addSeparator(); //插入分割线 183 | popMenu->addAction(quitAction); 184 | //popMenu->exec(); //堵住 185 | popMenu->exec(QCursor::pos()); 186 | } 187 | 188 | double Widget::MaxDate(int m) 189 | { 190 | switch (m) 191 | { 192 | case 1: 193 | case 3: 194 | case 5: 195 | case 7: 196 | case 8: 197 | case 10: 198 | case 12: 199 | return 31.0; 200 | break; 201 | } 202 | return 30.0; 203 | } 204 | 205 | int Widget::Week(QString str, QStringList list) 206 | { 207 | for (int i = 0; i < 7; i++) 208 | { 209 | if (str == list[i]) 210 | { 211 | return i; 212 | } 213 | } 214 | return 0; 215 | } 216 | 217 | void Widget::createRightPopActions() 218 | { 219 | popMenu = new QMenu(this); 220 | popMenu->setStyleSheet(QStringLiteral("background-color: rgb(255, 255, 255);")); 221 | 222 | adjustTimeAction = new QAction(this); 223 | adjustTimeAction->setText(QStringLiteral("调整时间")); 224 | 225 | adjustDateAction = new QAction(this); 226 | adjustDateAction->setText(QStringLiteral("调整日期")); 227 | 228 | quitAction = new QAction(this); 229 | quitAction->setText(QStringLiteral("退出")); 230 | 231 | connect(quitAction, SIGNAL(triggered(bool)), //关联退出信号 232 | this, SLOT(close())); 233 | } 234 | 235 | void Widget::init() 236 | { 237 | /***************加载状态****************/ 238 | strListState.append(QString("上午")); 239 | strListState.append(QString("中午")); 240 | strListState.append(QString("下午")); 241 | strListState.append(QString("晚上")); 242 | /***************加载星期****************/ 243 | strListWeek.append(QString("周一")); 244 | strListWeek.append(QString("周二")); 245 | strListWeek.append(QString("周三")); 246 | strListWeek.append(QString("周四")); 247 | strListWeek.append(QString("周五")); 248 | strListWeek.append(QString("周六")); 249 | strListWeek.append(QString("周日")); 250 | /***************加载日期****************/ 251 | strListDate.append(QString("一")); 252 | strListDate.append(QString("二")); 253 | strListDate.append(QString("三")); 254 | strListDate.append(QString("四")); 255 | strListDate.append(QString("五")); 256 | strListDate.append(QString("六")); 257 | strListDate.append(QString("七")); 258 | strListDate.append(QString("八")); 259 | strListDate.append(QString("九")); 260 | strListDate.append(QString("十")); 261 | strListDate.append(QString("十一")); 262 | strListDate.append(QString("十二")); 263 | strListDate.append(QString("十三")); 264 | strListDate.append(QString("十四")); 265 | strListDate.append(QString("十五")); 266 | strListDate.append(QString("十六")); 267 | strListDate.append(QString("十七")); 268 | strListDate.append(QString("十八")); 269 | strListDate.append(QString("十九")); 270 | strListDate.append(QString("二十")); 271 | strListDate.append(QString("二十一")); 272 | strListDate.append(QString("二十二")); 273 | strListDate.append(QString("二十三")); 274 | strListDate.append(QString("二十四")); 275 | strListDate.append(QString("二十五")); 276 | strListDate.append(QString("二十六")); 277 | strListDate.append(QString("二十七")); 278 | strListDate.append(QString("二十八")); 279 | strListDate.append(QString("二十九")); 280 | strListDate.append(QString("三十")); 281 | strListDate.append(QString("三十一")); 282 | strListDate.append(QString("三十二")); 283 | strListDate.append(QString("三十三")); 284 | strListDate.append(QString("三十四")); 285 | strListDate.append(QString("三十五")); 286 | strListDate.append(QString("三十六")); 287 | strListDate.append(QString("三十七")); 288 | strListDate.append(QString("三十八")); 289 | strListDate.append(QString("三十九")); 290 | strListDate.append(QString("四十")); 291 | strListDate.append(QString("四十一")); 292 | strListDate.append(QString("四十二")); 293 | strListDate.append(QString("四十三")); 294 | strListDate.append(QString("四十四")); 295 | strListDate.append(QString("四十五")); 296 | strListDate.append(QString("四十六")); 297 | strListDate.append(QString("四十七")); 298 | strListDate.append(QString("四十八")); 299 | strListDate.append(QString("四十九")); 300 | strListDate.append(QString("五十")); 301 | strListDate.append(QString("五十一")); 302 | strListDate.append(QString("五十二")); 303 | strListDate.append(QString("五十三")); 304 | strListDate.append(QString("五十四")); 305 | strListDate.append(QString("五十五")); 306 | strListDate.append(QString("五十六")); 307 | strListDate.append(QString("五十七")); 308 | strListDate.append(QString("五十八")); 309 | strListDate.append(QString("五十九")); 310 | strListDate.append(QString("零")); 311 | } 312 | -------------------------------------------------------------------------------- /Clock/widget.h: -------------------------------------------------------------------------------- 1 | #ifndef WIDGET_H 2 | #define WIDGET_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | namespace Ui { 15 | class Widget; 16 | } 17 | 18 | class Widget : public QWidget 19 | { 20 | Q_OBJECT 21 | 22 | public: 23 | explicit Widget(QWidget *parent = 0); 24 | ~Widget(); 25 | 26 | private: 27 | Ui::Widget *ui; 28 | 29 | private: 30 | QTimer* time; //定时器 31 | QMenu *popMenu; //右键弹出式菜单 32 | QAction *adjustTimeAction; //右键弹出式菜单中的内容 调整时间 33 | QAction *adjustDateAction; //调整日期 34 | QAction *quitAction; //退出 35 | QStringList strListDate, strListState, strListWeek; 36 | protected: 37 | virtual void paintEvent(QPaintEvent *event); 38 | virtual void mousePressEvent(QMouseEvent *event); 39 | virtual void keyPressEvent(QKeyEvent *event); 40 | virtual void mouseDoubleClickEvent(QMouseEvent *event); 41 | virtual void contextMenuEvent(QContextMenuEvent *event); //右键弹出菜单 42 | 43 | private: 44 | double MaxDate(int m); 45 | int Week(QString str,QStringList list); 46 | void createRightPopActions(); //创建右键菜单 47 | void init(); 48 | 49 | }; 50 | 51 | #endif // WIDGET_H 52 | -------------------------------------------------------------------------------- /Clock/widget.ui: -------------------------------------------------------------------------------- 1 | 2 | Widget 3 | 4 | 5 | 6 | 0 7 | 0 8 | 400 9 | 300 10 | 11 | 12 | 13 | Widget 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /MD5/MD5.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2020-05-13T00:18:24 4 | # 5 | #------------------------------------------------- 6 | 7 | QT += core gui 8 | 9 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 10 | 11 | TARGET = MD5 12 | TEMPLATE = app 13 | 14 | # The following define makes your compiler emit warnings if you use 15 | # any feature of Qt which has been marked as deprecated (the exact warnings 16 | # depend on your compiler). Please consult the documentation of the 17 | # deprecated API in order to know how to port your code away from it. 18 | DEFINES += QT_DEPRECATED_WARNINGS 19 | 20 | # You can also make your code fail to compile if you use deprecated APIs. 21 | # In order to do so, uncomment the following line. 22 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 23 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 24 | 25 | CONFIG += c++11 26 | 27 | SOURCES += \ 28 | main.cpp \ 29 | widget.cpp \ 30 | Md5Check/md5check.cpp 31 | 32 | HEADERS += \ 33 | widget.h \ 34 | Md5Check/md5check.h 35 | 36 | FORMS += \ 37 | widget.ui 38 | 39 | # Default rules for deployment. 40 | qnx: target.path = /tmp/$${TARGET}/bin 41 | else: unix:!android: target.path = /opt/$${TARGET}/bin 42 | !isEmpty(target.path): INSTALLS += target 43 | -------------------------------------------------------------------------------- /MD5/Md5Check/md5check.cpp: -------------------------------------------------------------------------------- 1 | #include "md5check.h" 2 | 3 | 4 | 5 | Md5Check::Md5Check(QObject *parent) : QObject(parent) 6 | { 7 | 8 | } 9 | 10 | void Md5Check::getMd5CheckSumSlot(const QString &filePath) 11 | { 12 | QFile file(filePath); 13 | QByteArray md5Result; 14 | QFileInfo md5FileInfo; 15 | md5FileInfo = QFileInfo(filePath); /*获取文件信息,考虑到文件过大*/ 16 | 17 | int totalSize = md5FileInfo.size()/(1024*1024); /* 把Byte字节转换成M兆 */ 18 | if(md5FileInfo.size()%(1024*1024)>0) 19 | totalSize+=1; /* 多余补一 */ 20 | int currentSize = 0; /*当前进度,读取的M兆数*/ 21 | 22 | if(file.open(QIODevice::ReadOnly)) 23 | { 24 | QCryptographicHash hash(QCryptographicHash::Md5); 25 | while (!file.atEnd()) { //读取文件直到读物完整 26 | QByteArray content = file.read(1024*1024); /*每次读取一兆M*/ 27 | hash.addData(content); /*分段进程MD5累加*/ 28 | currentSize++; /*当前进度,进度加一*/ 29 | emit sendProgressBarSignal(totalSize,currentSize); /*传送百分比信号*/ 30 | } 31 | md5Result = hash.result().toHex(); /*MD5值为32位的十六进制数*/ 32 | emit sendMd5CheckSumSignal(md5Result); /*发送MD5结果*/ 33 | file.close(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /MD5/Md5Check/md5check.h: -------------------------------------------------------------------------------- 1 | #ifndef MD5CHECK_H 2 | #define MD5CHECK_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | class Md5Check : public QObject 11 | { 12 | Q_OBJECT 13 | public: 14 | explicit Md5Check(QObject *parent = nullptr); 15 | 16 | signals: 17 | void sendMd5CheckSumSignal(QByteArray); //反馈md5值到界面 18 | void sendProgressBarSignal(int, int); //反馈进度到界面 以生成进度条 19 | //已经处理的数据量 待处理的总量 20 | 21 | public slots: 22 | void getMd5CheckSumSlot(const QString &filePath); 23 | }; 24 | 25 | #endif // MD5CHECK_H 26 | -------------------------------------------------------------------------------- /MD5/main.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | 3 | 版权所有 (C), 2001-2011, DeRoy 4 | 5 | ****************************************************************************** 6 | 文 件 名 : main.cpp 7 | 版 本 号 : 初稿 8 | 作 者 : DeRoy 9 | 生成日期 : 2020年8月30日 10 | 最近修改 : 11 | 功能描述 : Tcp_Server 12 | 函数列表 : 13 | * 14 | * 15 | 16 | 修改历史 : 17 | 1.日 期 : 2020年8月30日 18 | 作 者 : DeRoy 19 | 修改内容 : 创建文件 20 | 21 | 微信公众号:编程学习基地 22 | 23 | ******************************************************************************/ 24 | #include "widget.h" 25 | #include 26 | 27 | int main(int argc, char *argv[]) 28 | { 29 | QApplication a(argc, argv); 30 | Widget w; 31 | w.show(); 32 | 33 | return a.exec(); 34 | } 35 | -------------------------------------------------------------------------------- /MD5/widget.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | #include "ui_widget.h" 3 | 4 | Widget::Widget(QWidget *parent) : 5 | QWidget(parent), 6 | ui(new Ui::Widget) 7 | { 8 | ui->setupUi(this); 9 | setWindowTitle(QString("MD5")); 10 | ValInit(); 11 | } 12 | 13 | Widget::~Widget() 14 | { 15 | md5Thread.exit(); 16 | md5Thread.wait(10*1000); 17 | delete ui; 18 | } 19 | 20 | void Widget::ValInit() 21 | { 22 | /*设置进度条进度为0*/ 23 | ui->progressBar->setValue(0); 24 | /*将IO操作放到线程中去执行,防止文件过大卡界面*/ 25 | mMd5CheckSum.moveToThread(&md5Thread); /*从一个object 移动到 一个thread*/ 26 | md5Thread.start(); /*开启线程*/ 27 | 28 | /* 绑定信号与槽 */ 29 | /* 关联MD5计算槽函数 让Md5Check对象开始计算MD5值 */ 30 | connect(this,SIGNAL(checkMd5SumSignal(QString)),&mMd5CheckSum,SLOT(getMd5CheckSumSlot(QString))); 31 | /*关联MD5结果返回信号,将MD5计算结果传递给Widget定义的槽函数recvMd5CheckSumSlot*/ 32 | connect(&mMd5CheckSum, SIGNAL(sendMd5CheckSumSignal(QByteArray)),this, SLOT(recvMd5CheckSumSlot(QByteArray))); 33 | /*关联MD5计算进度,将进度返回给Widget定义的槽函数recvProgressBarSlot*/ 34 | connect(&mMd5CheckSum, SIGNAL(sendProgressBarSignal(int,int)),this, SLOT(recvProgressBarSlot(int,int))); 35 | } 36 | 37 | void Widget::recvMd5CheckSumSlot(QByteArray result) 38 | { 39 | ui->textEdit->setText(result); /*将MD5计算结果显示到主界面*/ 40 | } 41 | 42 | void Widget::recvProgressBarSlot(int total, int current) 43 | { 44 | ui->progressBar->setMaximum(total); /* 设置进度条最大值 */ 45 | ui->progressBar->setValue(current); /* 设置当前进度 */ 46 | } 47 | 48 | void Widget::on_pushButton_clicked() 49 | { 50 | QFileInfo MD5Fileinfo; /* 文件信息 */ 51 | QString md5Filename = QFileDialog::getOpenFileName(this,"open"); 52 | 53 | MD5Fileinfo = QFileInfo(md5Filename); 54 | 55 | ui->lineEdit->clear(); /*清空Edit*/ 56 | ui->textEdit->clear(); 57 | if(MD5Fileinfo.exists()) 58 | { 59 | ui->lineEdit->setText(MD5Fileinfo.fileName()); 60 | emit checkMd5SumSignal(md5Filename); /*将打开的文件路径通过信号传递给Md5Check对象*/ 61 | } 62 | } 63 | 64 | void Widget::on_clipboard_button_clicked() 65 | { 66 | clip = QApplication::clipboard(); /*获取系统剪贴板*/ 67 | clip->setText(ui->textEdit->toPlainText()); /*设置系统剪贴板内容*/ 68 | } 69 | -------------------------------------------------------------------------------- /MD5/widget.h: -------------------------------------------------------------------------------- 1 | #ifndef WIDGET_H 2 | #define WIDGET_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include "Md5Check/md5check.h" 12 | 13 | namespace Ui { 14 | class Widget; 15 | } 16 | 17 | class Widget : public QWidget 18 | { 19 | Q_OBJECT 20 | 21 | public: 22 | explicit Widget(QWidget *parent = nullptr); 23 | ~Widget(); 24 | 25 | public: 26 | void ValInit(); 27 | 28 | signals: 29 | void checkMd5SumSignal(const QString &filePath); 30 | 31 | private slots: 32 | void recvMd5CheckSumSlot(QByteArray); 33 | void recvProgressBarSlot(int,int); 34 | 35 | void on_pushButton_clicked(); 36 | 37 | void on_clipboard_button_clicked(); 38 | 39 | private: 40 | Ui::Widget *ui; 41 | 42 | QThread md5Thread; //线程 43 | Md5Check mMd5CheckSum; 44 | QClipboard* clip; //剪切板 45 | }; 46 | 47 | #endif // WIDGET_H 48 | -------------------------------------------------------------------------------- /MD5/widget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Widget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 400 10 | 300 11 | 12 | 13 | 14 | Widget 15 | 16 | 17 | 18 | 19 | 11 20 | 40 21 | 251 22 | 192 23 | 24 | 25 | 26 | QTextEdit { 27 | border-style: none; 28 | border-radius: 5px; 29 | padding: 3px; 30 | background: transparent; 31 | border: 1px solid #3498db; 32 | } 33 | QTextEdit:focus { 34 | border: 2px solid #3498db; 35 | } 36 | QTextEdit:!enabled { 37 | color: #525252; 38 | } 39 | 40 | 41 | 42 | 43 | 44 | 11 45 | 12 46 | 251 47 | 20 48 | 49 | 50 | 51 | QLineEdit 52 | { 53 | border-style: none; 54 | border-radius: 5px; 55 | padding: 3px; 56 | background: transparent; 57 | border: 2px solid #3498db; 58 | } 59 | 60 | 61 | 62 | 63 | 64 | 290 65 | 10 66 | 91 67 | 31 68 | 69 | 70 | 71 | QPushButton{ 72 | 73 | color: rgb(255, 255, 255); 74 | border-style: solid; 75 | border-radius: 5px; 76 | background-color: rgb(6, 163, 220); 77 | } 78 | 79 | QPushButton:hover{ 80 | background-color: rgb(16, 196, 245); 81 | } 82 | 83 | QPushButton:pressed { 84 | background-color: rgb(3, 130, 176); 85 | } 86 | 87 | 88 | 选择文件 89 | 90 | 91 | 92 | 93 | 94 | 290 95 | 120 96 | 91 97 | 31 98 | 99 | 100 | 101 | QPushButton{ 102 | 103 | color: rgb(255, 255, 255); 104 | border-style: solid; 105 | border-radius: 5px; 106 | background-color: rgb(6, 163, 220); 107 | } 108 | 109 | QPushButton:hover{ 110 | background-color: rgb(16, 196, 245); 111 | } 112 | 113 | QPushButton:pressed { 114 | background-color: rgb(3, 130, 176); 115 | } 116 | 117 | 118 | 复制到粘贴板 119 | 120 | 121 | 122 | 123 | 124 | 10 125 | 250 126 | 251 127 | 21 128 | 129 | 130 | 131 | QProgressBar { 132 | border: 2px solid grey; 133 | border-radius: 5px; 134 | } 135 | 136 | QProgressBar::chunk { 137 | background-color: #05B8CC; 138 | width: 20px; 139 | } 140 | 141 | 142 | 24 143 | 144 | 145 | Qt::AlignCenter 146 | 147 | 148 | 149 | 150 | 151 | 290 152 | 240 153 | 91 154 | 31 155 | 156 | 157 | 158 | QPushButton{ 159 | 160 | color: rgb(255, 255, 255); 161 | border-style: solid; 162 | border-radius: 5px; 163 | background-color: rgb(6, 163, 220); 164 | } 165 | 166 | QPushButton:hover{ 167 | background-color: rgb(16, 196, 245); 168 | } 169 | 170 | QPushButton:pressed { 171 | background-color: rgb(3, 130, 176); 172 | } 173 | 174 | 175 | 关闭 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | pushButton_3 184 | clicked() 185 | Widget 186 | close() 187 | 188 | 189 | 335 190 | 255 191 | 192 | 193 | 386 194 | 228 195 | 196 | 197 | 198 | 199 | 200 | -------------------------------------------------------------------------------- /NotePad/NotePad.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2020-07-03T15:40:41 4 | # 5 | #------------------------------------------------- 6 | 7 | QT += core gui printsupport 8 | 9 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 10 | 11 | TARGET = NotePad 12 | TEMPLATE = app 13 | 14 | # The following define makes your compiler emit warnings if you use 15 | # any feature of Qt which has been marked as deprecated (the exact warnings 16 | # depend on your compiler). Please consult the documentation of the 17 | # deprecated API in order to know how to port your code away from it. 18 | DEFINES += QT_DEPRECATED_WARNINGS 19 | 20 | # You can also make your code fail to compile if you use deprecated APIs. 21 | # In order to do so, uncomment the following line. 22 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 23 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 24 | 25 | CONFIG += c++11 26 | 27 | SOURCES += \ 28 | main.cpp \ 29 | mainwindow.cpp \ 30 | highlighter.cpp 31 | 32 | HEADERS += \ 33 | mainwindow.h \ 34 | highlighter.h 35 | 36 | FORMS += \ 37 | mainwindow.ui 38 | 39 | # Default rules for deployment. 40 | qnx: target.path = /tmp/$${TARGET}/bin 41 | else: unix:!android: target.path = /opt/$${TARGET}/bin 42 | !isEmpty(target.path): INSTALLS += target 43 | 44 | RESOURCES += \ 45 | src.qrc 46 | -------------------------------------------------------------------------------- /NotePad/highlighter.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of the examples of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:BSD$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and The Qt Company. For licensing terms 14 | ** and conditions see https://www.qt.io/terms-conditions. For further 15 | ** information use the contact form at https://www.qt.io/contact-us. 16 | ** 17 | ** BSD License Usage 18 | ** Alternatively, you may use this file under the terms of the BSD license 19 | ** as follows: 20 | ** 21 | ** "Redistribution and use in source and binary forms, with or without 22 | ** modification, are permitted provided that the following conditions are 23 | ** met: 24 | ** * Redistributions of source code must retain the above copyright 25 | ** notice, this list of conditions and the following disclaimer. 26 | ** * Redistributions in binary form must reproduce the above copyright 27 | ** notice, this list of conditions and the following disclaimer in 28 | ** the documentation and/or other materials provided with the 29 | ** distribution. 30 | ** * Neither the name of The Qt Company Ltd nor the names of its 31 | ** contributors may be used to endorse or promote products derived 32 | ** from this software without specific prior written permission. 33 | ** 34 | ** 35 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 36 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 37 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 38 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 39 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 40 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 41 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 42 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 43 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 44 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 45 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." 46 | ** 47 | ** $QT_END_LICENSE$ 48 | ** 49 | ****************************************************************************/ 50 | 51 | #include "highlighter.h" 52 | 53 | //! [0] 54 | Highlighter::Highlighter(QTextDocument *parent) 55 | : QSyntaxHighlighter(parent) 56 | { 57 | HighlightingRule rule; 58 | 59 | keywordFormat.setForeground(Qt::darkBlue); 60 | keywordFormat.setFontWeight(QFont::Bold); 61 | QStringList keywordPatterns; 62 | keywordPatterns << "\\bchar\\b" << "\\bclass\\b" << "\\bconst\\b" 63 | << "\\bdouble\\b" << "\\benum\\b" << "\\bexplicit\\b" 64 | << "\\bfriend\\b" << "\\binline\\b" << "\\bint\\b" 65 | << "\\blong\\b" << "\\bnamespace\\b" << "\\boperator\\b" 66 | << "\\bprivate\\b" << "\\bprotected\\b" << "\\bpublic\\b" 67 | << "\\bshort\\b" << "\\bsignals\\b" << "\\bsigned\\b" 68 | << "\\bslots\\b" << "\\bstatic\\b" << "\\bstruct\\b" 69 | << "\\btemplate\\b" << "\\btypedef\\b" << "\\btypename\\b" 70 | << "\\bunion\\b" << "\\bunsigned\\b" << "\\bvirtual\\b" 71 | << "\\bvoid\\b" << "\\bvolatile\\b" << "\\bbool\\b"; 72 | foreach (const QString &pattern, keywordPatterns) { 73 | rule.pattern = QRegularExpression(pattern); 74 | rule.format = keywordFormat; 75 | highlightingRules.append(rule); 76 | //! [0] //! [1] 77 | } 78 | //! [1] 79 | 80 | //! [2] 81 | classFormat.setFontWeight(QFont::Bold); 82 | classFormat.setForeground(Qt::darkMagenta); 83 | rule.pattern = QRegularExpression("\\bQ[A-Za-z]+\\b"); 84 | rule.format = classFormat; 85 | highlightingRules.append(rule); 86 | //! [2] 87 | 88 | //! [3] 89 | singleLineCommentFormat.setForeground(Qt::red); 90 | rule.pattern = QRegularExpression("//[^\n]*"); 91 | rule.format = singleLineCommentFormat; 92 | highlightingRules.append(rule); 93 | 94 | multiLineCommentFormat.setForeground(Qt::red); 95 | //! [3] 96 | 97 | //! [4] 98 | quotationFormat.setForeground(Qt::darkGreen); 99 | rule.pattern = QRegularExpression("\".*\""); 100 | rule.format = quotationFormat; 101 | highlightingRules.append(rule); 102 | //! [4] 103 | 104 | //! [5] 105 | functionFormat.setFontItalic(true); 106 | functionFormat.setForeground(Qt::blue); 107 | rule.pattern = QRegularExpression("\\b[A-Za-z0-9_]+(?=\\()"); 108 | rule.format = functionFormat; 109 | highlightingRules.append(rule); 110 | //! [5] 111 | 112 | //! [6] 113 | commentStartExpression = QRegularExpression("/\\*"); 114 | commentEndExpression = QRegularExpression("\\*/"); 115 | } 116 | //! [6] 117 | 118 | //! [7] 119 | void Highlighter::highlightBlock(const QString &text) 120 | { 121 | foreach (const HighlightingRule &rule, highlightingRules) { 122 | QRegularExpressionMatchIterator matchIterator = rule.pattern.globalMatch(text); 123 | while (matchIterator.hasNext()) { 124 | QRegularExpressionMatch match = matchIterator.next(); 125 | setFormat(match.capturedStart(), match.capturedLength(), rule.format); 126 | } 127 | } 128 | //! [7] //! [8] 129 | setCurrentBlockState(0); 130 | //! [8] 131 | 132 | //! [9] 133 | int startIndex = 0; 134 | if (previousBlockState() != 1) 135 | startIndex = text.indexOf(commentStartExpression); 136 | 137 | //! [9] //! [10] 138 | while (startIndex >= 0) { 139 | //! [10] //! [11] 140 | QRegularExpressionMatch match = commentEndExpression.match(text, startIndex); 141 | int endIndex = match.capturedStart(); 142 | int commentLength = 0; 143 | if (endIndex == -1) { 144 | setCurrentBlockState(1); 145 | commentLength = text.length() - startIndex; 146 | } else { 147 | commentLength = endIndex - startIndex 148 | + match.capturedLength(); 149 | } 150 | setFormat(startIndex, commentLength, multiLineCommentFormat); 151 | startIndex = text.indexOf(commentStartExpression, startIndex + commentLength); 152 | } 153 | } 154 | //! [11] 155 | -------------------------------------------------------------------------------- /NotePad/highlighter.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of the examples of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:BSD$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and The Qt Company. For licensing terms 14 | ** and conditions see https://www.qt.io/terms-conditions. For further 15 | ** information use the contact form at https://www.qt.io/contact-us. 16 | ** 17 | ** BSD License Usage 18 | ** Alternatively, you may use this file under the terms of the BSD license 19 | ** as follows: 20 | ** 21 | ** "Redistribution and use in source and binary forms, with or without 22 | ** modification, are permitted provided that the following conditions are 23 | ** met: 24 | ** * Redistributions of source code must retain the above copyright 25 | ** notice, this list of conditions and the following disclaimer. 26 | ** * Redistributions in binary form must reproduce the above copyright 27 | ** notice, this list of conditions and the following disclaimer in 28 | ** the documentation and/or other materials provided with the 29 | ** distribution. 30 | ** * Neither the name of The Qt Company Ltd nor the names of its 31 | ** contributors may be used to endorse or promote products derived 32 | ** from this software without specific prior written permission. 33 | ** 34 | ** 35 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 36 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 37 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 38 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 39 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 40 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 41 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 42 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 43 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 44 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 45 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." 46 | ** 47 | ** $QT_END_LICENSE$ 48 | ** 49 | ****************************************************************************/ 50 | 51 | #ifndef HIGHLIGHTER_H 52 | #define HIGHLIGHTER_H 53 | 54 | #include 55 | #include 56 | #include 57 | 58 | QT_BEGIN_NAMESPACE 59 | class QTextDocument; 60 | QT_END_NAMESPACE 61 | 62 | //! [0] 63 | class Highlighter : public QSyntaxHighlighter 64 | { 65 | Q_OBJECT 66 | 67 | public: 68 | Highlighter(QTextDocument *parent = 0); 69 | 70 | protected: 71 | void highlightBlock(const QString &text) override; 72 | 73 | private: 74 | struct HighlightingRule 75 | { 76 | QRegularExpression pattern; 77 | QTextCharFormat format; 78 | }; 79 | QVector highlightingRules; 80 | 81 | QRegularExpression commentStartExpression; 82 | QRegularExpression commentEndExpression; 83 | 84 | QTextCharFormat keywordFormat; 85 | QTextCharFormat classFormat; 86 | QTextCharFormat singleLineCommentFormat; 87 | QTextCharFormat multiLineCommentFormat; 88 | QTextCharFormat quotationFormat; 89 | QTextCharFormat functionFormat; 90 | }; 91 | //! [0] 92 | 93 | #endif // HIGHLIGHTER_H 94 | -------------------------------------------------------------------------------- /NotePad/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication a(argc, argv); 7 | MainWindow w; 8 | w.show(); 9 | 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /NotePad/mainwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include "ui_mainwindow.h" 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | 20 | MainWindow::MainWindow(QWidget *parent) : 21 | QMainWindow(parent), 22 | ui(new Ui::MainWindow) 23 | { 24 | ui->setupUi(this); 25 | Init(); 26 | on_newActiona_triggered(); 27 | } 28 | 29 | MainWindow::~MainWindow() 30 | { 31 | delete ui; 32 | } 33 | 34 | void MainWindow::Init() 35 | { 36 | this->Tab = new QTabWidget(this); 37 | this->setCentralWidget(Tab); 38 | this->Tab->setMovable(true); //设置页面是否可被拖拽移动. 39 | this->Tab->setTabsClosable(true); //设置页面是否可以关闭 40 | /*设置一秒定时器*/ 41 | this->timer = new QTimer(this); 42 | timer->start(1000); 43 | 44 | 45 | connect(this->Tab, SIGNAL(tabCloseRequested(int)), this, SLOT(Del_Tab(int)));//关联删除信号才可以删除tab 46 | connect(this->Tab, SIGNAL(currentChanged(int)), this, SLOT(tabChange(int)));//关联TabWidget改变信号 47 | connect(ui->openAction,SIGNAL(triggered()),this,SLOT(on_actiona_open_triggered())); /*打开文件 工具栏里面的打开 多加的*/ 48 | connect(ui->saveAction,SIGNAL(triggered()),this,SLOT(on_actiona_saveFile_triggered())); /*保存文件*/ 49 | connect(ui->actiona_exit, SIGNAL(triggered()), this, SLOT(close())); /*退出程序*/ 50 | connect(this->timer, SIGNAL(timeout()), this, SLOT(flushTime())); /*刷新时间*/ 51 | 52 | this->filename = "new"; 53 | this->ID = 0; 54 | 55 | //状态栏状态信息初始化 56 | this->stbar = this->statusBar(); 57 | this->lb_fileinfo = new QLabel(); 58 | this->lb_time = new QLabel(); 59 | this->lab_tmp = new QLabel(" "); 60 | this->lab_tmp1 = new QLabel(" "); 61 | //添加状态栏信息 62 | stbar->addWidget(lb_fileinfo); 63 | stbar->addWidget(lab_tmp); 64 | stbar->addWidget(lab_tmp1); 65 | stbar->addWidget(lb_time); 66 | } 67 | 68 | /* 转CSDN */ 69 | void MainWindow::on_actiona_CSDN_triggered() 70 | { 71 | QDesktopServices::openUrl(QUrl(QLatin1String("https://blog.csdn.net/qq_44519484"))); 72 | } 73 | 74 | /* 新建文件 */ 75 | void MainWindow::on_newActiona_triggered() 76 | { 77 | QFont font; 78 | font.setFamily("Consolas"); 79 | font.setFixedPitch(true); 80 | font.setPointSize(12); 81 | 82 | QTextEdit *newEdit = new QTextEdit(); 83 | /*设置撤销和返回*/ 84 | connect(newEdit->document(), &QTextDocument::undoAvailable, 85 | ui->undoAction, &QAction::setEnabled); 86 | connect(newEdit->document(), &QTextDocument::redoAvailable, 87 | ui->actionRedo, &QAction::setEnabled); 88 | connect(newEdit,SIGNAL(cursorPositionChanged()),this,SLOT(cursorChanged())); 89 | ui->undoAction->setEnabled(newEdit->document()->isUndoAvailable()); 90 | ui->actionRedo->setEnabled(newEdit->document()->isUndoAvailable()); 91 | /*设置字体*/ 92 | newEdit->setFont(font); 93 | QFontMetrics metrics(newEdit->font()); 94 | newEdit->setTabStopWidth(4 * metrics.width(' ')); //设置tab键为4个空格 95 | Highlighter*newLight = new Highlighter(newEdit->document()); //设置语法高亮 96 | EditList.append(newEdit); //将newEdit添加进List里面,方便管理 97 | highlighterList.append(newLight); //将newLight添加进List里面,方便管理 98 | this->Tab->addTab(newEdit, filename); //新建空白文件 99 | this->Tab->setCurrentIndex(ID); //设置当前Tab 100 | 101 | this->ID++; //id加一 102 | this->lb_fileinfo->setText(filename); 103 | qDebug()<<"ID:"<lb_fileinfo->setText(filename); 129 | this->on_newActiona_triggered(); //新建空白TextEdit窗口 130 | this->Tab->setCurrentIndex(ID - 1); 131 | 132 | //读取 解决打开文件中文乱码 没有完全解决 133 | while (!file.atEnd()) { 134 | QByteArray line = file.readLine(); 135 | QString str = QString(line); //QString(line) QByteArray转化为QString 136 | this->EditList.at(ID - 1)->append(str); 137 | } 138 | file.close(); 139 | qDebug()<<"读取文件成功"; 140 | filename = "new"; 141 | } 142 | 143 | /* 删除tab */ 144 | void MainWindow::Del_Tab(int index) 145 | { 146 | this->Tab->removeTab(index); 147 | //从列表中删除 148 | this->EditList.removeAt(index); 149 | this->highlighterList.removeAt(index); 150 | ID--; 151 | qDebug()<<"ID:"<currentIndex()<<"index:"<lb_fileinfo->setText(this->Tab->tabText(index)); 160 | } 161 | 162 | /* 保存文件 */ 163 | void MainWindow::on_actiona_saveFile_triggered() 164 | { 165 | QString saveFileName = QFileDialog::getSaveFileName(this, "保存",QString("%1.txt").arg(ID)); 166 | if(saveFileName.isEmpty()){ 167 | qDebug()<<"文件保存失败"; 168 | return; 169 | } 170 | //获取文件名 171 | QFileInfo fileinfo; 172 | fileinfo = QFileInfo(saveFileName); 173 | this->lb_fileinfo->setText(fileinfo.fileName()); 174 | //更改文件名 175 | this->Tab->setTabText(Tab->currentIndex(),fileinfo.fileName()); 176 | 177 | //进行写操作 178 | QString txt = this->EditList.at(this->Tab->currentIndex())->toPlainText(); 179 | QFile file(saveFileName); 180 | file.open(QIODevice::WriteOnly|QIODevice::Text); 181 | file.write(txt.toUtf8()); 182 | file.close(); 183 | qDebug()<<"文件保存成功"; 184 | } 185 | 186 | /* 另存为 */ 187 | void MainWindow::on_actiona_save_triggered() 188 | { 189 | QString saveFileName = QFileDialog::getSaveFileName(this, "保存", "./"); 190 | if(saveFileName.isEmpty()){ 191 | qDebug()<<"文件保存失败"; 192 | return; 193 | } 194 | //获取文件名 195 | QFileInfo fileinfo; 196 | fileinfo = QFileInfo(saveFileName); 197 | this->lb_fileinfo->setText(fileinfo.fileName()); 198 | //更改文件名 199 | this->Tab->setTabText(Tab->currentIndex(),fileinfo.fileName()); 200 | 201 | //进行写操作 202 | QString txt = this->EditList.at(this->Tab->currentIndex())->toPlainText(); 203 | QFile file(saveFileName); 204 | file.open(QIODevice::WriteOnly|QIODevice::Text); 205 | file.write(txt.toUtf8()); 206 | file.close(); 207 | qDebug()<<"文件保存成功"; 208 | } 209 | 210 | /* 刷新时间 */ 211 | void MainWindow::flushTime() 212 | { 213 | this->currentTime = QDateTime::currentDateTime(); 214 | QString str = this->currentTime.toString("yyyy-MM-dd hh:mm:ss ddd"); //设置显示格式 215 | this->lb_time->setText(" 当前时间: "+str);//在标签上显示时间 216 | } 217 | 218 | /* 打开新窗口 */ 219 | void MainWindow::on_actiona_new_triggered() 220 | { 221 | MainWindow* newWindow = new MainWindow; 222 | newWindow->show(); 223 | } 224 | 225 | /* 打印 */ 226 | void MainWindow::on_actiona_Painter_triggered() 227 | { 228 | //创建打印机对象 229 | QPrinter printer (QPrinter::HighResolution); 230 | //打印机构造一个新的模态打印机对话框。 231 | QPrintDialog *dlg=new QPrintDialog(&printer,this); 232 | //如果选中文档 activeWindow为QTextEdit 声明的对象 233 | if(this->EditList.at(this->Tab->currentIndex())->textCursor().hasSelection()) 234 | { 235 | dlg->addEnabledOption(QAbstractPrintDialog::PrintSelection); 236 | } 237 | dlg->setWindowTitle(tr("打印文档")); 238 | if(dlg->exec()==QDialog::Accepted) 239 | { 240 | //便于将文本编辑文档打印到给定打印机的功能。这相当于直接在文档上调用print方法 241 | this->EditList.at(this->Tab->currentIndex())->print(&printer); 242 | } 243 | delete dlg; 244 | } 245 | 246 | /* 打印预览 */ 247 | void MainWindow::on_action_PrintPreview_triggered() 248 | { 249 | QPrinter printer(QPrinter::HighResolution); 250 | QPrintPreviewDialog preview(&printer, this); 251 | connect(&preview, SIGNAL(paintRequested(QPrinter*)), this,SLOT(printPreview(QPrinter*))); 252 | preview.exec(); 253 | } 254 | 255 | /* 预览槽函数 */ 256 | void MainWindow::printPreview(QPrinter *printer) 257 | { 258 | this->EditList.at(this->Tab->currentIndex())->print(printer); 259 | } 260 | 261 | /* 自动换行 */ 262 | void MainWindow::on_actiona_auto_triggered() 263 | { 264 | //QTextEdit默认自动换行 265 | if(ui->actiona_auto->isChecked()){ 266 | qDebug()<<"checked"; 267 | for(int i=0;isetWordWrapMode(QTextOption::WrapAnywhere); 270 | } 271 | } 272 | else { 273 | for(int i=0;isetWordWrapMode(QTextOption::NoWrap); 276 | } 277 | } 278 | } 279 | 280 | /* 另存为pdf */ 281 | void MainWindow::on_action_pdf_triggered() 282 | { 283 | QString saveFileName = QFileDialog::getSaveFileName(this, "另存为PDF",QString("%1.pdf").arg(ID)); 284 | if(saveFileName.isEmpty()){ 285 | qDebug()<<"文件保存失败"; 286 | return; 287 | } 288 | 289 | QPrinter printer(QPrinter::HighResolution); 290 | printer.setOutputFormat(QPrinter::PdfFormat); 291 | printer.setOutputFileName(saveFileName); 292 | this->EditList.at(this->Tab->currentIndex())->document()->print(&printer); 293 | 294 | } 295 | 296 | void MainWindow::on_actiona_font_triggered() 297 | { 298 | bool ok; 299 | QFont font = QFontDialog::getFont(&ok, QFont("Consolas", 12), this); 300 | if (ok) { 301 | for(int i=0;isetFont(font); 304 | } 305 | qDebug()<<"成功设置颜色"; 306 | } else { 307 | qDebug()<<"颜色设置失败"; 308 | } 309 | } 310 | 311 | void MainWindow::on_undoAction_triggered() 312 | { 313 | EditList.at(Tab->currentIndex())->undo(); //撤销 314 | } 315 | 316 | void MainWindow::on_actionRedo_triggered() 317 | { 318 | EditList.at(Tab->currentIndex())->redo(); //返回 319 | } 320 | 321 | void MainWindow::on_actiona_copy_triggered() 322 | { 323 | EditList.at(Tab->currentIndex())->copy(); //复制 324 | } 325 | 326 | void MainWindow::on_actiona_paste_triggered() 327 | { 328 | EditList.at(Tab->currentIndex())->paste(); //粘贴 329 | } 330 | 331 | void MainWindow::on_actiona_cat_triggered() 332 | { 333 | EditList.at(Tab->currentIndex())->cut(); //剪贴 334 | } 335 | 336 | void MainWindow::on_actiona_all_triggered() 337 | { 338 | EditList.at(Tab->currentIndex())->selectAll(); //全选 339 | } 340 | 341 | void MainWindow::on_actiona_about_triggered() 342 | { 343 | QMessageBox::about(this, tr("关于"), tr("这是一个基于 Qt5 实现的NotePad软件\r\n具备类似 记事本 NotePad++ 的功能。")); 344 | } 345 | 346 | void MainWindow::cursorChanged() 347 | { 348 | // currentCursor = EditList.at(Tab->currentIndex())->textCursor(); 349 | // QString selextStr = EditList.at(Tab->currentIndex())->textCursor().selectedText(); 350 | // if (selextStr.isEmpty()) { 351 | // if(isundo) 352 | // { 353 | // isundo = false; 354 | // //EditList.at(Tab->currentIndex())->undo(); 355 | // } 356 | // } 357 | // else { 358 | // if(isundo) 359 | // { 360 | // isundo = false; 361 | // EditList.at(Tab->currentIndex())->undo(); 362 | // } 363 | // findText(selextStr); 364 | // isundo = true; 365 | // } 366 | // EditList.at(Tab->currentIndex())->setTextCursor(currentCursor); 367 | } 368 | 369 | void MainWindow::findText(QString selextStr) 370 | { 371 | QTextDocument *document = EditList.at(Tab->currentIndex())->document(); //QTextDocument富文本文档 372 | 373 | /* 374 | * QTextCursor是专门用来协助处理和获取QTextDocument内容的一组api. 375 | * 它包含的信息既有QTextDocument内的光标位置(position()), 376 | * 以及所做的selection(anchor() 和 position()之间)。 377 | * current character是指position之前的那个character. 378 | * current block是指包含position()位置的block. 379 | */ 380 | QTextCursor highlightCursor(document); //编辑QTextDocument对象 381 | QTextCursor cursor(document); //编辑QTextDocument对象 382 | 383 | cursor.beginEditBlock(); 384 | 385 | 386 | QTextCharFormat plainFormat(highlightCursor.charFormat()); //取得format信息 387 | QTextCharFormat colorFormat = plainFormat; //设置信息 388 | 389 | //colorFormat.setForeground(Qt::green); 390 | colorFormat.setBackground(Qt::green); //设置背景为绿色 391 | 392 | while (!highlightCursor.isNull() && !highlightCursor.atEnd()) { 393 | highlightCursor = document->find(selextStr, highlightCursor, 394 | QTextDocument::FindWholeWords); 395 | 396 | if (!highlightCursor.isNull()) { 397 | 398 | highlightCursor.movePosition(QTextCursor::WordRight, 399 | QTextCursor::KeepAnchor); 400 | highlightCursor.mergeCharFormat(colorFormat); 401 | } 402 | } 403 | 404 | cursor.endEditBlock(); 405 | 406 | } 407 | 408 | void MainWindow::on_actiona_data_triggered() 409 | { 410 | EditList.at(Tab->currentIndex())->append("时间:" + this->currentTime.toString("yyyy-MM-dd hh:mm:ss ddd")); 411 | } 412 | -------------------------------------------------------------------------------- /NotePad/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include "highlighter.h" 11 | 12 | namespace Ui { 13 | class MainWindow; 14 | } 15 | 16 | class MainWindow : public QMainWindow 17 | { 18 | Q_OBJECT 19 | 20 | public: 21 | explicit MainWindow(QWidget *parent = nullptr); 22 | ~MainWindow(); 23 | void Init(); 24 | private slots: 25 | void Del_Tab(int); 26 | void flushTime(); 27 | void printPreview(QPrinter *); 28 | void tabChange(int); 29 | void cursorChanged(); 30 | void findText(QString); 31 | private slots: 32 | void on_actiona_CSDN_triggered(); //转CSDN 33 | 34 | void on_newActiona_triggered(); //新建文件 35 | 36 | void on_actiona_open_triggered(); //打开文件 37 | 38 | void on_actiona_saveFile_triggered();//保存文件 39 | 40 | void on_actiona_save_triggered(); //另存为 41 | 42 | void on_actiona_new_triggered(); 43 | 44 | void on_actiona_Painter_triggered(); 45 | 46 | void on_action_PrintPreview_triggered(); 47 | 48 | void on_actiona_auto_triggered(); 49 | 50 | void on_action_pdf_triggered(); 51 | 52 | void on_actiona_font_triggered(); 53 | 54 | void on_undoAction_triggered(); 55 | 56 | void on_actionRedo_triggered(); 57 | 58 | void on_actiona_copy_triggered(); 59 | 60 | void on_actiona_paste_triggered(); 61 | 62 | void on_actiona_cat_triggered(); 63 | 64 | void on_actiona_all_triggered(); 65 | 66 | void on_actiona_about_triggered(); 67 | 68 | void on_actiona_data_triggered(); 69 | 70 | private: 71 | Ui::MainWindow *ui; 72 | 73 | // QTextCursor currentCursor; //当前光标位置 74 | 75 | QStatusBar *stbar; 76 | QLabel *lb_fileinfo; 77 | QLabel *lb_time; 78 | QLabel *lab_tmp; 79 | QLabel *lab_tmp1; 80 | 81 | QTabWidget *Tab; 82 | QString filename; 83 | QList EditList; /* 定义QList容器 */ 84 | QList highlighterList; 85 | int ID; /* textedit ID */ 86 | 87 | //状态栏显示时间 88 | QDateTime currentTime; 89 | QTimer *timer; 90 | }; 91 | 92 | #endif // MAINWINDOW_H 93 | -------------------------------------------------------------------------------- /NotePad/mainwindow.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 593 10 | 457 11 | 12 | 13 | 14 | MainWindow 15 | 16 | 17 | 18 | 19 | 20 | 0 21 | 0 22 | 593 23 | 23 24 | 25 | 26 | 27 | 28 | 文件(F) 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 编辑(E) 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 格式(O) 58 | 59 | 60 | 61 | 62 | 63 | 64 | 查看(V) 65 | 66 | 67 | 68 | 69 | 70 | 71 | 帮助(H) 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | TopToolBarArea 86 | 87 | 88 | false 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | :/src/file_new.png:/src/file_new.png 103 | 104 | 105 | 新建(N) 106 | 107 | 108 | Ctrl+N 109 | 110 | 111 | 112 | 113 | 114 | :/src/view_zoom.png:/src/view_zoom.png 115 | 116 | 117 | 新窗口(M) 118 | 119 | 120 | Ctrl+Shift+N 121 | 122 | 123 | 124 | 125 | 126 | :/src/file_open.png:/src/file_open.png 127 | 128 | 129 | 打开(O) 130 | 131 | 132 | Ctrl+O 133 | 134 | 135 | 136 | 137 | 138 | :/src/file_save.png:/src/file_save.png 139 | 140 | 141 | 保存(S) 142 | 143 | 144 | Ctrl+S 145 | 146 | 147 | 148 | 149 | 150 | :/src/file_saveas.png:/src/file_saveas.png 151 | 152 | 153 | 另存为(A) 154 | 155 | 156 | Ctrl+Shift+S 157 | 158 | 159 | 160 | 161 | 162 | :/src/file_print.png:/src/file_print.png 163 | 164 | 165 | 打印(P) 166 | 167 | 168 | Ctrl+P 169 | 170 | 171 | 172 | 173 | 174 | :/src/close.png:/src/close.png 175 | 176 | 177 | 退出(X) 178 | 179 | 180 | 181 | 182 | 183 | :/src/editredo.png:/src/editredo.png 184 | 185 | 186 | 返回 187 | 188 | 189 | 返回 190 | 191 | 192 | Ctrl+Z 193 | 194 | 195 | 196 | 197 | 198 | :/src/editcut.png:/src/editcut.png 199 | 200 | 201 | 剪贴(T) 202 | 203 | 204 | Ctrl+X 205 | 206 | 207 | 208 | 209 | 210 | :/src/editcopy.png:/src/editcopy.png 211 | 212 | 213 | 复制(C) 214 | 215 | 216 | Ctrl+C 217 | 218 | 219 | 220 | 221 | 222 | :/src/editpaste.png:/src/editpaste.png 223 | 224 | 225 | 粘贴(P) 226 | 227 | 228 | Ctrl+V 229 | 230 | 231 | 232 | 233 | 234 | :/src/edit_find_n.png:/src/edit_find_n.png 235 | 236 | 237 | 查找(F) 238 | 239 | 240 | Ctrl+F 241 | 242 | 243 | 244 | 245 | 全选(A) 246 | 247 | 248 | Ctrl+A 249 | 250 | 251 | 252 | 253 | 时间/日期(D) 254 | 255 | 256 | F6 257 | 258 | 259 | 260 | 261 | true 262 | 263 | 264 | true 265 | 266 | 267 | 自动换行(W) 268 | 269 | 270 | 271 | 272 | 273 | :/src/form_font.png:/src/form_font.png 274 | 275 | 276 | 字体(F) 277 | 278 | 279 | 280 | 281 | 缩放(Z) 282 | 283 | 284 | 285 | 286 | 状态栏(S) 287 | 288 | 289 | 290 | 291 | 查看帮助(H) 292 | 293 | 294 | 295 | 296 | 297 | :/src/deroy.jpg:/src/deroy.jpg 298 | 299 | 300 | 技术支持(F) 301 | 302 | 303 | 304 | 305 | 关于记事本(A) 306 | 307 | 308 | 309 | 310 | 311 | :/src/file_save.png:/src/file_save.png 312 | 313 | 314 | 保存 315 | 316 | 317 | 318 | 319 | 320 | :/src/editundo.png:/src/editundo.png 321 | 322 | 323 | 撤销 324 | 325 | 326 | 327 | 328 | 329 | :/src/edit_find_n.png:/src/edit_find_n.png 330 | 331 | 332 | 查找 333 | 334 | 335 | 336 | 337 | 338 | :/src/fileprint.png:/src/fileprint.png 339 | 340 | 341 | 打印预览 342 | 343 | 344 | 345 | 346 | 347 | :/src/exportpdf.png:/src/exportpdf.png 348 | 349 | 350 | 另存为pdf 351 | 352 | 353 | Ctrl+D 354 | 355 | 356 | 357 | 358 | 359 | :/src/file_open.png:/src/file_open.png 360 | 361 | 362 | 打开 363 | 364 | 365 | 打开 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | -------------------------------------------------------------------------------- /NotePad/src.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | src/close.png 4 | src/edit_all.png 5 | src/edit_bing.png 6 | src/edit_copy.png 7 | src/edit_cut.png 8 | src/edit_date.png 9 | src/edit_del.png 10 | src/edit_find.png 11 | src/edit_find_n.png 12 | src/edit_goto.png 13 | src/edit_past.png 14 | src/edit_replace.png 15 | src/edit_undo.png 16 | src/file_close.png 17 | src/file_exit.png 18 | src/file_new.png 19 | src/file_open.png 20 | src/file_print.png 21 | src/file_pset.png 22 | src/file_save.png 23 | src/file_saveas.png 24 | src/form_autoline.png 25 | src/form_color.png 26 | src/form_font.png 27 | src/help.png 28 | src/help_about.png 29 | src/help_csdn.png 30 | src/icon.png 31 | src/view_status.png 32 | src/view_zoom.png 33 | src/editcopy.png 34 | src/editcut.png 35 | src/editpaste.png 36 | src/editredo.png 37 | src/editundo.png 38 | src/exportpdf.png 39 | src/filenew.png 40 | src/fileopen.png 41 | src/fileprint.png 42 | src/filesave.png 43 | src/textbold.png 44 | src/textcenter.png 45 | src/textitalic.png 46 | src/textjustify.png 47 | src/textleft.png 48 | src/textright.png 49 | src/textunder.png 50 | src/zoomin.png 51 | src/zoomout.png 52 | src/deroy.jpg 53 | 54 | 55 | -------------------------------------------------------------------------------- /NotePad/src/close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/NotePad/src/close.png -------------------------------------------------------------------------------- /NotePad/src/deroy.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/NotePad/src/deroy.jpg -------------------------------------------------------------------------------- /NotePad/src/edit_all.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/NotePad/src/edit_all.png -------------------------------------------------------------------------------- /NotePad/src/edit_bing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/NotePad/src/edit_bing.png -------------------------------------------------------------------------------- /NotePad/src/edit_copy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/NotePad/src/edit_copy.png -------------------------------------------------------------------------------- /NotePad/src/edit_cut.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/NotePad/src/edit_cut.png -------------------------------------------------------------------------------- /NotePad/src/edit_date.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/NotePad/src/edit_date.png -------------------------------------------------------------------------------- /NotePad/src/edit_del.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/NotePad/src/edit_del.png -------------------------------------------------------------------------------- /NotePad/src/edit_find.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/NotePad/src/edit_find.png -------------------------------------------------------------------------------- /NotePad/src/edit_find_n.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/NotePad/src/edit_find_n.png -------------------------------------------------------------------------------- /NotePad/src/edit_goto.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/NotePad/src/edit_goto.png -------------------------------------------------------------------------------- /NotePad/src/edit_past.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/NotePad/src/edit_past.png -------------------------------------------------------------------------------- /NotePad/src/edit_replace.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/NotePad/src/edit_replace.png -------------------------------------------------------------------------------- /NotePad/src/edit_undo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/NotePad/src/edit_undo.png -------------------------------------------------------------------------------- /NotePad/src/editcopy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/NotePad/src/editcopy.png -------------------------------------------------------------------------------- /NotePad/src/editcut.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/NotePad/src/editcut.png -------------------------------------------------------------------------------- /NotePad/src/editpaste.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/NotePad/src/editpaste.png -------------------------------------------------------------------------------- /NotePad/src/editredo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/NotePad/src/editredo.png -------------------------------------------------------------------------------- /NotePad/src/editundo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/NotePad/src/editundo.png -------------------------------------------------------------------------------- /NotePad/src/exportpdf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/NotePad/src/exportpdf.png -------------------------------------------------------------------------------- /NotePad/src/file_close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/NotePad/src/file_close.png -------------------------------------------------------------------------------- /NotePad/src/file_exit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/NotePad/src/file_exit.png -------------------------------------------------------------------------------- /NotePad/src/file_new.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/NotePad/src/file_new.png -------------------------------------------------------------------------------- /NotePad/src/file_open.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/NotePad/src/file_open.png -------------------------------------------------------------------------------- /NotePad/src/file_print.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/NotePad/src/file_print.png -------------------------------------------------------------------------------- /NotePad/src/file_pset.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/NotePad/src/file_pset.png -------------------------------------------------------------------------------- /NotePad/src/file_save.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/NotePad/src/file_save.png -------------------------------------------------------------------------------- /NotePad/src/file_saveas.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/NotePad/src/file_saveas.png -------------------------------------------------------------------------------- /NotePad/src/filenew.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/NotePad/src/filenew.png -------------------------------------------------------------------------------- /NotePad/src/fileopen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/NotePad/src/fileopen.png -------------------------------------------------------------------------------- /NotePad/src/fileprint.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/NotePad/src/fileprint.png -------------------------------------------------------------------------------- /NotePad/src/filesave.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/NotePad/src/filesave.png -------------------------------------------------------------------------------- /NotePad/src/form_autoline.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/NotePad/src/form_autoline.png -------------------------------------------------------------------------------- /NotePad/src/form_color.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/NotePad/src/form_color.png -------------------------------------------------------------------------------- /NotePad/src/form_font.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/NotePad/src/form_font.png -------------------------------------------------------------------------------- /NotePad/src/help.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/NotePad/src/help.png -------------------------------------------------------------------------------- /NotePad/src/help_about.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/NotePad/src/help_about.png -------------------------------------------------------------------------------- /NotePad/src/help_csdn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/NotePad/src/help_csdn.png -------------------------------------------------------------------------------- /NotePad/src/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/NotePad/src/icon.png -------------------------------------------------------------------------------- /NotePad/src/textbold.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/NotePad/src/textbold.png -------------------------------------------------------------------------------- /NotePad/src/textcenter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/NotePad/src/textcenter.png -------------------------------------------------------------------------------- /NotePad/src/textitalic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/NotePad/src/textitalic.png -------------------------------------------------------------------------------- /NotePad/src/textjustify.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/NotePad/src/textjustify.png -------------------------------------------------------------------------------- /NotePad/src/textleft.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/NotePad/src/textleft.png -------------------------------------------------------------------------------- /NotePad/src/textright.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/NotePad/src/textright.png -------------------------------------------------------------------------------- /NotePad/src/textunder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/NotePad/src/textunder.png -------------------------------------------------------------------------------- /NotePad/src/view_status.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/NotePad/src/view_status.png -------------------------------------------------------------------------------- /NotePad/src/view_zoom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/NotePad/src/view_zoom.png -------------------------------------------------------------------------------- /NotePad/src/zoomin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/NotePad/src/zoomin.png -------------------------------------------------------------------------------- /NotePad/src/zoomout.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/NotePad/src/zoomout.png -------------------------------------------------------------------------------- /QRunnable_QThreadPoll/QRunnable_QThreadPoll.pro: -------------------------------------------------------------------------------- 1 | QT -= gui 2 | QT += core 3 | CONFIG += c++11 console 4 | CONFIG -= app_bundle 5 | 6 | # The following define makes your compiler emit warnings if you use 7 | # any Qt feature that has been marked deprecated (the exact warnings 8 | # depend on your compiler). Please consult the documentation of the 9 | # deprecated API in order to know how to port your code away from it. 10 | DEFINES += QT_DEPRECATED_WARNINGS 11 | 12 | # You can also make your code fail to compile if it uses deprecated APIs. 13 | # In order to do so, uncomment the following line. 14 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 15 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 16 | 17 | SOURCES += \ 18 | main.cpp \ 19 | myrunable.cpp 20 | 21 | # Default rules for deployment. 22 | qnx: target.path = /tmp/$${TARGET}/bin 23 | else: unix:!android: target.path = /opt/$${TARGET}/bin 24 | !isEmpty(target.path): INSTALLS += target 25 | 26 | HEADERS += \ 27 | myrunable.h 28 | -------------------------------------------------------------------------------- /QRunnable_QThreadPoll/main.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | 3 | 版权所有 (C), 2001-2011, DeRoy 4 | 5 | ****************************************************************************** 6 | 文 件 名 : main.cpp 7 | 版 本 号 : 初稿 8 | 作 者 : DeRoy 9 | 生成日期 : 2020年9月7日 10 | 最近修改 : 11 | 功能描述 : QThreadPool_Demo 12 | 函数列表 : 13 | * 14 | * 15 | 16 | 修改历史 : 17 | 1.日 期 : 2020年9月7日 18 | 作 者 : DeRoy 19 | 修改内容 : 创建文件 20 | 21 | ******************************************************************************/ 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include"myrunable.h" 28 | 29 | int main(int argc, char *argv[]) 30 | { 31 | QCoreApplication a(argc, argv); 32 | qDebug()<setMaxThreadCount(15); //设置线程池最大线程数量 35 | MyRunable* task = new MyRunable(); 36 | task->setAutoDelete(true); //autoDelete属性默认为true QThreadPool会在run()函数运行结束后,自动删除了MyTask对象 37 | QThreadPool::globalInstance()->start(task); //任务放进线程池 38 | QThread::sleep(1); 39 | MyRunable* task1 = new MyRunable(); 40 | task1->setAutoDelete(true); 41 | QThreadPool::globalInstance()->start(task1); 42 | 43 | QThreadPool::globalInstance()->waitForDone(); //等待任务结束 44 | qDebug() << "end"; 45 | return a.exec(); 46 | } 47 | -------------------------------------------------------------------------------- /QRunnable_QThreadPoll/myrunable.cpp: -------------------------------------------------------------------------------- 1 | #include "myrunable.h" 2 | 3 | 4 | MyRunable::MyRunable(QObject *parent) : QObject(parent) 5 | { 6 | 7 | } 8 | 9 | MyRunable::~MyRunable() 10 | { 11 | qDebug()<<"delete Task"; 12 | } 13 | 14 | void MyRunable::run() 15 | { 16 | int i = 10; 17 | while(i--) 18 | { 19 | qDebug() << "线程id:"<< QThread::currentThreadId()<< QString(":剩余%1").arg(i); 20 | QThread::sleep(1); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /QRunnable_QThreadPoll/myrunable.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | 3 | 版权所有 (C), 2001-2011, DeRoy 4 | 5 | ****************************************************************************** 6 | 文 件 名 : myrunable.h 7 | 版 本 号 : 初稿 8 | 作 者 : DeRoy 9 | 生成日期 : 2020年9月7日 10 | 最近修改 : 11 | 功能描述 : QThreadPool_Demo 12 | 函数列表 : 13 | * 14 | * 15 | 16 | 修改历史 : 17 | 1.日 期 : 2020年9月7日 18 | 作 者 : DeRoy 19 | 修改内容 : 创建文件 20 | 21 | ******************************************************************************/ 22 | 23 | 24 | #ifndef MYRUNABLE_H 25 | #define MYRUNABLE_H 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | class MyRunable : public QObject, public QRunnable 33 | { 34 | Q_OBJECT 35 | public: 36 | explicit MyRunable(QObject *parent = nullptr); 37 | ~MyRunable(); 38 | protected: 39 | void run(); 40 | }; 41 | 42 | #endif // MYRUNABLE_H 43 | -------------------------------------------------------------------------------- /QThread_Demo_console/QThread_Demo_console.pro: -------------------------------------------------------------------------------- 1 | QT -= gui 2 | 3 | CONFIG += c++11 console 4 | CONFIG -= app_bundle 5 | 6 | # The following define makes your compiler emit warnings if you use 7 | # any Qt feature that has been marked deprecated (the exact warnings 8 | # depend on your compiler). Please consult the documentation of the 9 | # deprecated API in order to know how to port your code away from it. 10 | DEFINES += QT_DEPRECATED_WARNINGS 11 | 12 | # You can also make your code fail to compile if it uses deprecated APIs. 13 | # In order to do so, uncomment the following line. 14 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 15 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 16 | 17 | SOURCES += \ 18 | main.cpp \ 19 | mythread.cpp 20 | 21 | # Default rules for deployment. 22 | qnx: target.path = /tmp/$${TARGET}/bin 23 | else: unix:!android: target.path = /opt/$${TARGET}/bin 24 | !isEmpty(target.path): INSTALLS += target 25 | 26 | HEADERS += \ 27 | mythread.h 28 | -------------------------------------------------------------------------------- /QThread_Demo_console/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include"mythread.h" 5 | int main(int argc, char *argv[]) 6 | { 7 | QCoreApplication a(argc, argv); 8 | qDebug()<<"main a.exec() :"< 3 | MyThread::MyThread() 4 | { 5 | qDebug()<<"MyThread::MyThread:"<=0); 17 | } 18 | -------------------------------------------------------------------------------- /QThread_Demo_console/mythread.h: -------------------------------------------------------------------------------- 1 | #ifndef MYTHREAD_H 2 | #define MYTHREAD_H 3 | #include 4 | #include 5 | 6 | class MyThread : public QThread 7 | { 8 | Q_OBJECT 9 | public: 10 | MyThread(); 11 | protected: 12 | virtual void run(); 13 | private: 14 | }; 15 | #endif // MYTHREAD_H 16 | -------------------------------------------------------------------------------- /QThread_Demo_console/readme.txt: -------------------------------------------------------------------------------- 1 | 重写QThread类实现多线程 -------------------------------------------------------------------------------- /QThread_QMutex_Demo/QThread_QMutex_Demo.pro: -------------------------------------------------------------------------------- 1 | QT -= gui 2 | 3 | CONFIG += c++11 console 4 | CONFIG -= app_bundle 5 | 6 | # The following define makes your compiler emit warnings if you use 7 | # any Qt feature that has been marked deprecated (the exact warnings 8 | # depend on your compiler). Please consult the documentation of the 9 | # deprecated API in order to know how to port your code away from it. 10 | DEFINES += QT_DEPRECATED_WARNINGS 11 | 12 | # You can also make your code fail to compile if it uses deprecated APIs. 13 | # In order to do so, uncomment the following line. 14 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 15 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 16 | 17 | SOURCES += \ 18 | main.cpp \ 19 | mythread.cpp 20 | 21 | # Default rules for deployment. 22 | qnx: target.path = /tmp/$${TARGET}/bin 23 | else: unix:!android: target.path = /opt/$${TARGET}/bin 24 | !isEmpty(target.path): INSTALLS += target 25 | 26 | HEADERS += \ 27 | mythread.h 28 | -------------------------------------------------------------------------------- /QThread_QMutex_Demo/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "mythread.h" 3 | int global_Val = 100; 4 | QMutex globlMutex; 5 | int main(int argc, char *argv[]) 6 | { 7 | QCoreApplication a(argc, argv); 8 | MyThread thread1,thread2; 9 | thread1.start(); 10 | thread2.start(); 11 | return a.exec(); 12 | } 13 | -------------------------------------------------------------------------------- /QThread_QMutex_Demo/mythread.cpp: -------------------------------------------------------------------------------- 1 | #include "mythread.h" 2 | #include 3 | extern int global_Val; 4 | extern QMutex globlMutex; //锁一定是全局的 5 | MyThread::MyThread() 6 | { 7 | qDebug()<<"mainThread::currentId:"<0) { 13 | QMutexLocker locker(&globlMutex); 14 | qDebug()<<"threadId:"<< QThread::currentThreadId()<<" global_val:"< 4 | #include 5 | #include 6 | 7 | class MyThread : public QThread 8 | { 9 | Q_OBJECT 10 | public: 11 | MyThread(); 12 | protected: 13 | virtual void run(); 14 | private: 15 | }; 16 | #endif // MYTHREAD_H 17 | -------------------------------------------------------------------------------- /QThread_QWaitCondition_Demo/QThread_QWaitCondition_Demo.pro: -------------------------------------------------------------------------------- 1 | QT -= gui 2 | 3 | CONFIG += c++11 console 4 | CONFIG -= app_bundle 5 | 6 | # The following define makes your compiler emit warnings if you use 7 | # any Qt feature that has been marked deprecated (the exact warnings 8 | # depend on your compiler). Please consult the documentation of the 9 | # deprecated API in order to know how to port your code away from it. 10 | DEFINES += QT_DEPRECATED_WARNINGS 11 | 12 | # You can also make your code fail to compile if it uses deprecated APIs. 13 | # In order to do so, uncomment the following line. 14 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 15 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 16 | 17 | SOURCES += \ 18 | main.cpp 19 | 20 | # Default rules for deployment. 21 | qnx: target.path = /tmp/$${TARGET}/bin 22 | else: unix:!android: target.path = /opt/$${TARGET}/bin 23 | !isEmpty(target.path): INSTALLS += target 24 | -------------------------------------------------------------------------------- /QThread_QWaitCondition_Demo/main.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | 3 | 版权所有 (C), 2001-2011, DeRoy 4 | 5 | ****************************************************************************** 6 | 文 件 名 : main.cpp 7 | 版 本 号 : 初稿 8 | 作 者 : DeRoy 9 | 生成日期 : 2020年9月7日 10 | 最近修改 : 11 | 功能描述 : Tcp_Server 12 | 函数列表 : 13 | * 14 | * 15 | 16 | 修改历史 : 17 | 1.日 期 : 2020年9月7日 18 | 作 者 : DeRoy 19 | 修改内容 : 创建文件 20 | 21 | 微信公众号:编程学习基地 22 | 23 | ******************************************************************************/ 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #define BUFFER_SIZE 2 31 | 32 | /*生产者*/ 33 | class producons 34 | { 35 | public: 36 | int buffer[BUFFER_SIZE]; /*数据*/ 37 | QMutex lock; //互斥锁 38 | int readpos,writepos; //读写位置 39 | QWaitCondition nottempty; //条件变量 没有空间 40 | QWaitCondition notfull; //条件变量 没有货物 41 | 42 | producons() 43 | { 44 | readpos = writepos = 0; 45 | } 46 | }; 47 | producons buffer; //生产者对象 48 | 49 | class Producor:public QThread 50 | { 51 | public: 52 | void run(); 53 | void put(producons * prod,int data); 54 | }; 55 | 56 | void Producor::run() 57 | { 58 | int n; 59 | for(n = 0;n<5;n++) 60 | { 61 | qDebug()<<"生产者睡眠 1s..."; 62 | sleep(1); 63 | qDebug()<<"生产信息:" << n; 64 | put(&buffer, n); 65 | } 66 | for(n=5; n<10; n++) 67 | { 68 | qDebug()<<"生产者睡眠 3s..."; 69 | sleep(3); 70 | qDebug()<<"生产信息:"<< n; 71 | put(&buffer,n); 72 | } 73 | put(&buffer, -1); 74 | qDebug()<<"结束生产者!\n"; 75 | return; 76 | } 77 | void Producor::put(producons *prod, int data) 78 | { 79 | prod->lock.lock(); 80 | 81 | //write until buffer not full 82 | while((prod->writepos + 1)%BUFFER_SIZE == prod->readpos) 83 | { 84 | qDebug()<<"生产者等待生产,直到buffer有空位置"; 85 | prod->notfull.wait(&prod->lock); 86 | } 87 | //将数据写入到buffer里面去 88 | prod->buffer[prod->writepos] = data; 89 | prod->writepos++; 90 | if(prod->writepos >= BUFFER_SIZE) 91 | prod->writepos = 0; 92 | //仓库已满,等待消费者消费 93 | prod->nottempty.wakeAll(); 94 | prod->lock.unlock(); 95 | } 96 | 97 | class Consumer:public QThread 98 | { 99 | public: 100 | void run(); 101 | int get(producons *prod); 102 | }; 103 | 104 | void Consumer::run() 105 | { 106 | int d = 0; 107 | while(1) 108 | { 109 | qDebug()<<"消费者睡眠 2s..."; 110 | sleep(2); 111 | d = get(&buffer); 112 | qDebug()<<"读取信息:"<< d; 113 | if(d == -1) break; 114 | } 115 | qDebug()<<"结束消费者!"; 116 | return; 117 | } 118 | 119 | int Consumer::get(producons *prod) 120 | { 121 | int data; 122 | prod->lock.lock(); //加锁 123 | 124 | while(prod->writepos == prod->readpos) 125 | { 126 | qDebug()<<"消费者等待,直到buffer有消息\n"; 127 | prod->nottempty.wait(&prod->lock); 128 | } 129 | //读取buffer里面的消息 130 | data = prod->buffer[prod->readpos]; 131 | prod->readpos++; 132 | 133 | if(prod->readpos >=BUFFER_SIZE) 134 | prod->readpos = 0; 135 | //触发非满条件变量 告诉生产者可以生产 136 | prod->notfull.wakeAll(); 137 | prod->lock.unlock(); 138 | 139 | return data; 140 | } 141 | int main(int argc, char *argv[]) 142 | { 143 | QCoreApplication a(argc, argv); 144 | Producor productor; 145 | Consumer consumer; 146 | productor.start(); 147 | consumer.start(); 148 | productor.wait(); 149 | consumer.wait(); 150 | return a.exec(); 151 | } 152 | -------------------------------------------------------------------------------- /Qt_Linguist _Demo/build-language_demo-Desktop_Qt_5_12_1_MinGW_64_bit-Debug/.qmake.stash: -------------------------------------------------------------------------------- 1 | QMAKE_CXX.QT_COMPILER_STDCXX = 201402L 2 | QMAKE_CXX.QMAKE_GCC_MAJOR_VERSION = 7 3 | QMAKE_CXX.QMAKE_GCC_MINOR_VERSION = 3 4 | QMAKE_CXX.QMAKE_GCC_PATCH_VERSION = 0 5 | QMAKE_CXX.COMPILER_MACROS = \ 6 | QT_COMPILER_STDCXX \ 7 | QMAKE_GCC_MAJOR_VERSION \ 8 | QMAKE_GCC_MINOR_VERSION \ 9 | QMAKE_GCC_PATCH_VERSION 10 | QMAKE_CXX.INCDIRS = \ 11 | D:/qt/Tools/mingw730_64/lib/gcc/x86_64-w64-mingw32/7.3.0/include/c++ \ 12 | D:/qt/Tools/mingw730_64/lib/gcc/x86_64-w64-mingw32/7.3.0/include/c++/x86_64-w64-mingw32 \ 13 | D:/qt/Tools/mingw730_64/lib/gcc/x86_64-w64-mingw32/7.3.0/include/c++/backward \ 14 | D:/qt/Tools/mingw730_64/lib/gcc/x86_64-w64-mingw32/7.3.0/include \ 15 | D:/qt/Tools/mingw730_64/lib/gcc/x86_64-w64-mingw32/7.3.0/include-fixed \ 16 | D:/qt/Tools/mingw730_64/x86_64-w64-mingw32/include 17 | QMAKE_CXX.LIBDIRS = \ 18 | D:/qt/Tools/mingw730_64/lib/gcc/x86_64-w64-mingw32/7.3.0 \ 19 | D:/qt/Tools/mingw730_64/lib/gcc \ 20 | D:/qt/Tools/mingw730_64/x86_64-w64-mingw32/lib \ 21 | D:/qt/Tools/mingw730_64/lib 22 | -------------------------------------------------------------------------------- /Qt_Linguist _Demo/build-language_demo-Desktop_Qt_5_12_1_MinGW_64_bit-Debug/Translate_CN.qm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/Qt_Linguist _Demo/build-language_demo-Desktop_Qt_5_12_1_MinGW_64_bit-Debug/Translate_CN.qm -------------------------------------------------------------------------------- /Qt_Linguist _Demo/build-language_demo-Desktop_Qt_5_12_1_MinGW_64_bit-Debug/Translate_EN.qm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/Qt_Linguist _Demo/build-language_demo-Desktop_Qt_5_12_1_MinGW_64_bit-Debug/Translate_EN.qm -------------------------------------------------------------------------------- /Qt_Linguist _Demo/build-language_demo-Desktop_Qt_5_12_1_MinGW_64_bit-Debug/debug/language_demo.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/Qt_Linguist _Demo/build-language_demo-Desktop_Qt_5_12_1_MinGW_64_bit-Debug/debug/language_demo.exe -------------------------------------------------------------------------------- /Qt_Linguist _Demo/build-language_demo-Desktop_Qt_5_12_1_MinGW_64_bit-Debug/debug/main.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/Qt_Linguist _Demo/build-language_demo-Desktop_Qt_5_12_1_MinGW_64_bit-Debug/debug/main.o -------------------------------------------------------------------------------- /Qt_Linguist _Demo/build-language_demo-Desktop_Qt_5_12_1_MinGW_64_bit-Debug/debug/mainwindow.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/Qt_Linguist _Demo/build-language_demo-Desktop_Qt_5_12_1_MinGW_64_bit-Debug/debug/mainwindow.o -------------------------------------------------------------------------------- /Qt_Linguist _Demo/build-language_demo-Desktop_Qt_5_12_1_MinGW_64_bit-Debug/debug/moc_mainwindow.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** Meta object code from reading C++ file 'mainwindow.h' 3 | ** 4 | ** Created by: The Qt Meta Object Compiler version 67 (Qt 5.12.1) 5 | ** 6 | ** WARNING! All changes made in this file will be lost! 7 | *****************************************************************************/ 8 | 9 | #include "../../language/mainwindow.h" 10 | #include 11 | #include 12 | #if !defined(Q_MOC_OUTPUT_REVISION) 13 | #error "The header file 'mainwindow.h' doesn't include ." 14 | #elif Q_MOC_OUTPUT_REVISION != 67 15 | #error "This file was generated using the moc from 5.12.1. It" 16 | #error "cannot be used with the include files from this version of Qt." 17 | #error "(The moc has changed too much.)" 18 | #endif 19 | 20 | QT_BEGIN_MOC_NAMESPACE 21 | QT_WARNING_PUSH 22 | QT_WARNING_DISABLE_DEPRECATED 23 | struct qt_meta_stringdata_MainWindow_t { 24 | QByteArrayData data[4]; 25 | char stringdata0[70]; 26 | }; 27 | #define QT_MOC_LITERAL(idx, ofs, len) \ 28 | Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(len, \ 29 | qptrdiff(offsetof(qt_meta_stringdata_MainWindow_t, stringdata0) + ofs \ 30 | - idx * sizeof(QByteArrayData)) \ 31 | ) 32 | static const qt_meta_stringdata_MainWindow_t qt_meta_stringdata_MainWindow = { 33 | { 34 | QT_MOC_LITERAL(0, 0, 10), // "MainWindow" 35 | QT_MOC_LITERAL(1, 11, 28), // "on_actiona_chinese_triggered" 36 | QT_MOC_LITERAL(2, 40, 0), // "" 37 | QT_MOC_LITERAL(3, 41, 28) // "on_actionb_English_triggered" 38 | 39 | }, 40 | "MainWindow\0on_actiona_chinese_triggered\0" 41 | "\0on_actionb_English_triggered" 42 | }; 43 | #undef QT_MOC_LITERAL 44 | 45 | static const uint qt_meta_data_MainWindow[] = { 46 | 47 | // content: 48 | 8, // revision 49 | 0, // classname 50 | 0, 0, // classinfo 51 | 2, 14, // methods 52 | 0, 0, // properties 53 | 0, 0, // enums/sets 54 | 0, 0, // constructors 55 | 0, // flags 56 | 0, // signalCount 57 | 58 | // slots: name, argc, parameters, tag, flags 59 | 1, 0, 24, 2, 0x08 /* Private */, 60 | 3, 0, 25, 2, 0x08 /* Private */, 61 | 62 | // slots: parameters 63 | QMetaType::Void, 64 | QMetaType::Void, 65 | 66 | 0 // eod 67 | }; 68 | 69 | void MainWindow::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a) 70 | { 71 | if (_c == QMetaObject::InvokeMetaMethod) { 72 | auto *_t = static_cast(_o); 73 | Q_UNUSED(_t) 74 | switch (_id) { 75 | case 0: _t->on_actiona_chinese_triggered(); break; 76 | case 1: _t->on_actionb_English_triggered(); break; 77 | default: ; 78 | } 79 | } 80 | Q_UNUSED(_a); 81 | } 82 | 83 | QT_INIT_METAOBJECT const QMetaObject MainWindow::staticMetaObject = { { 84 | &QMainWindow::staticMetaObject, 85 | qt_meta_stringdata_MainWindow.data, 86 | qt_meta_data_MainWindow, 87 | qt_static_metacall, 88 | nullptr, 89 | nullptr 90 | } }; 91 | 92 | 93 | const QMetaObject *MainWindow::metaObject() const 94 | { 95 | return QObject::d_ptr->metaObject ? QObject::d_ptr->dynamicMetaObject() : &staticMetaObject; 96 | } 97 | 98 | void *MainWindow::qt_metacast(const char *_clname) 99 | { 100 | if (!_clname) return nullptr; 101 | if (!strcmp(_clname, qt_meta_stringdata_MainWindow.stringdata0)) 102 | return static_cast(this); 103 | return QMainWindow::qt_metacast(_clname); 104 | } 105 | 106 | int MainWindow::qt_metacall(QMetaObject::Call _c, int _id, void **_a) 107 | { 108 | _id = QMainWindow::qt_metacall(_c, _id, _a); 109 | if (_id < 0) 110 | return _id; 111 | if (_c == QMetaObject::InvokeMetaMethod) { 112 | if (_id < 2) 113 | qt_static_metacall(this, _c, _id, _a); 114 | _id -= 2; 115 | } else if (_c == QMetaObject::RegisterMethodArgumentMetaType) { 116 | if (_id < 2) 117 | *reinterpret_cast(_a[0]) = -1; 118 | _id -= 2; 119 | } 120 | return _id; 121 | } 122 | QT_WARNING_POP 123 | QT_END_MOC_NAMESPACE 124 | -------------------------------------------------------------------------------- /Qt_Linguist _Demo/build-language_demo-Desktop_Qt_5_12_1_MinGW_64_bit-Debug/debug/moc_mainwindow.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/Qt_Linguist _Demo/build-language_demo-Desktop_Qt_5_12_1_MinGW_64_bit-Debug/debug/moc_mainwindow.o -------------------------------------------------------------------------------- /Qt_Linguist _Demo/build-language_demo-Desktop_Qt_5_12_1_MinGW_64_bit-Debug/debug/moc_predefs.h: -------------------------------------------------------------------------------- 1 | #define __DBL_MIN_EXP__ (-1021) 2 | #define __FLT32X_MAX_EXP__ 1024 3 | #define __cpp_attributes 200809 4 | #define __UINT_LEAST16_MAX__ 0xffff 5 | #define __ATOMIC_ACQUIRE 2 6 | #define __FLT128_MAX_10_EXP__ 4932 7 | #define __FLT_MIN__ 1.17549435082228750796873653722224568e-38F 8 | #define __GCC_IEC_559_COMPLEX 2 9 | #define __cpp_aggregate_nsdmi 201304 10 | #define __UINT_LEAST8_TYPE__ unsigned char 11 | #define __SIZEOF_FLOAT80__ 16 12 | #define _WIN32 1 13 | #define __INTMAX_C(c) c ## LL 14 | #define __CHAR_BIT__ 8 15 | #define __UINT8_MAX__ 0xff 16 | #define _WIN64 1 17 | #define __WINT_MAX__ 0xffff 18 | #define __FLT32_MIN_EXP__ (-125) 19 | #define __cpp_static_assert 200410 20 | #define __ORDER_LITTLE_ENDIAN__ 1234 21 | #define __SIZE_MAX__ 0xffffffffffffffffULL 22 | #define __WCHAR_MAX__ 0xffff 23 | #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1 24 | #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 1 25 | #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1 26 | #define __DBL_DENORM_MIN__ double(4.94065645841246544176568792868221372e-324L) 27 | #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1 28 | #define __GCC_ATOMIC_CHAR_LOCK_FREE 2 29 | #define __GCC_IEC_559 2 30 | #define __FLT32X_DECIMAL_DIG__ 17 31 | #define __FLT_EVAL_METHOD__ 0 32 | #define __cpp_binary_literals 201304 33 | #define __FLT64_DECIMAL_DIG__ 17 34 | #define __GCC_ATOMIC_CHAR32_T_LOCK_FREE 2 35 | #define __x86_64 1 36 | #define __cpp_variadic_templates 200704 37 | #define __UINT_FAST64_MAX__ 0xffffffffffffffffULL 38 | #define __SIG_ATOMIC_TYPE__ int 39 | #define __DBL_MIN_10_EXP__ (-307) 40 | #define __FINITE_MATH_ONLY__ 0 41 | #define __cpp_variable_templates 201304 42 | #define __GNUC_PATCHLEVEL__ 0 43 | #define __FLT32_HAS_DENORM__ 1 44 | #define __UINT_FAST8_MAX__ 0xff 45 | #define __has_include(STR) __has_include__(STR) 46 | #define _stdcall __attribute__((__stdcall__)) 47 | #define __DEC64_MAX_EXP__ 385 48 | #define __INT8_C(c) c 49 | #define __INT_LEAST8_WIDTH__ 8 50 | #define __UINT_LEAST64_MAX__ 0xffffffffffffffffULL 51 | #define __SHRT_MAX__ 0x7fff 52 | #define __LDBL_MAX__ 1.18973149535723176502126385303097021e+4932L 53 | #define __FLT64X_MAX_10_EXP__ 4932 54 | #define __UINT_LEAST8_MAX__ 0xff 55 | #define __GCC_ATOMIC_BOOL_LOCK_FREE 2 56 | #define __FLT128_DENORM_MIN__ 6.47517511943802511092443895822764655e-4966F128 57 | #define __UINTMAX_TYPE__ long long unsigned int 58 | #define __DEC32_EPSILON__ 1E-6DF 59 | #define __FLT_EVAL_METHOD_TS_18661_3__ 0 60 | #define __UINT32_MAX__ 0xffffffffU 61 | #define __GXX_EXPERIMENTAL_CXX0X__ 1 62 | #define __LDBL_MAX_EXP__ 16384 63 | #define __FLT128_MIN_EXP__ (-16381) 64 | #define __WINT_MIN__ 0 65 | #define __FLT128_MIN_10_EXP__ (-4931) 66 | #define __INT_LEAST16_WIDTH__ 16 67 | #define __SCHAR_MAX__ 0x7f 68 | #define __FLT128_MANT_DIG__ 113 69 | #define __WCHAR_MIN__ 0 70 | #define __INT64_C(c) c ## LL 71 | #define __DBL_DIG__ 15 72 | #define __GCC_ATOMIC_POINTER_LOCK_FREE 2 73 | #define __FLT64X_MANT_DIG__ 64 74 | #define __SIZEOF_INT__ 4 75 | #define __SIZEOF_POINTER__ 8 76 | #define __GCC_ATOMIC_CHAR16_T_LOCK_FREE 2 77 | #define __USER_LABEL_PREFIX__ 78 | #define __FLT64X_EPSILON__ 1.08420217248550443400745280086994171e-19F64x 79 | #define __STDC_HOSTED__ 1 80 | #define __WIN32 1 81 | #define __LDBL_HAS_INFINITY__ 1 82 | #define __WIN64 1 83 | #define __FLT32_DIG__ 6 84 | #define __FLT_EPSILON__ 1.19209289550781250000000000000000000e-7F 85 | #define __GXX_WEAK__ 1 86 | #define __SHRT_WIDTH__ 16 87 | #define __LDBL_MIN__ 3.36210314311209350626267781732175260e-4932L 88 | #define __DEC32_MAX__ 9.999999E96DF 89 | #define __cpp_threadsafe_static_init 200806 90 | #define __FLT64X_DENORM_MIN__ 3.64519953188247460252840593361941982e-4951F64x 91 | #define __MINGW32__ 1 92 | #define __FLT32X_HAS_INFINITY__ 1 93 | #define __INT32_MAX__ 0x7fffffff 94 | #define __INT_WIDTH__ 32 95 | #define __SIZEOF_LONG__ 4 96 | #define __UINT16_C(c) c 97 | #define __PTRDIFF_WIDTH__ 64 98 | #define __DECIMAL_DIG__ 21 99 | #define __FLT64_EPSILON__ 2.22044604925031308084726333618164062e-16F64 100 | #define __INTMAX_WIDTH__ 64 101 | #define __FLT64_MIN_EXP__ (-1021) 102 | #define __has_include_next(STR) __has_include_next__(STR) 103 | #define __FLT64X_MIN_10_EXP__ (-4931) 104 | #define __LDBL_HAS_QUIET_NAN__ 1 105 | #define __FLT64_MANT_DIG__ 53 106 | #define _REENTRANT 1 107 | #define __GNUC__ 7 108 | #define _cdecl __attribute__((__cdecl__)) 109 | #define __GXX_RTTI 1 110 | #define __MMX__ 1 111 | #define __cpp_delegating_constructors 200604 112 | #define __FLT_HAS_DENORM__ 1 113 | #define __SIZEOF_LONG_DOUBLE__ 16 114 | #define __BIGGEST_ALIGNMENT__ 16 115 | #define __STDC_UTF_16__ 1 116 | #define __FLT64_MAX_10_EXP__ 308 117 | #define __FLT32_HAS_INFINITY__ 1 118 | #define __DBL_MAX__ double(1.79769313486231570814527423731704357e+308L) 119 | #define _thiscall __attribute__((__thiscall__)) 120 | #define __cpp_raw_strings 200710 121 | #define __INT_FAST32_MAX__ 0x7fffffff 122 | #define __WINNT 1 123 | #define __DBL_HAS_INFINITY__ 1 124 | #define __INT64_MAX__ 0x7fffffffffffffffLL 125 | #define __WINNT__ 1 126 | #define __DEC32_MIN_EXP__ (-94) 127 | #define __INTPTR_WIDTH__ 64 128 | #define __FLT32X_HAS_DENORM__ 1 129 | #define __INT_FAST16_TYPE__ short int 130 | #define _fastcall __attribute__((__fastcall__)) 131 | #define __LDBL_HAS_DENORM__ 1 132 | #define __cplusplus 201402L 133 | #define __cpp_ref_qualifiers 200710 134 | #define __DEC128_MAX__ 9.999999999999999999999999999999999E6144DL 135 | #define __INT_LEAST32_MAX__ 0x7fffffff 136 | #define __DEC32_MIN__ 1E-95DF 137 | #define __DEPRECATED 1 138 | #define __cpp_rvalue_references 200610 139 | #define __DBL_MAX_EXP__ 1024 140 | #define __WCHAR_WIDTH__ 16 141 | #define __FLT32_MAX__ 3.40282346638528859811704183484516925e+38F32 142 | #define __DEC128_EPSILON__ 1E-33DL 143 | #define __SSE2_MATH__ 1 144 | #define __ATOMIC_HLE_RELEASE 131072 145 | #define __WIN32__ 1 146 | #define __PTRDIFF_MAX__ 0x7fffffffffffffffLL 147 | #define __amd64 1 148 | #define __tune_core2__ 1 149 | #define __ATOMIC_HLE_ACQUIRE 65536 150 | #define __FLT32_HAS_QUIET_NAN__ 1 151 | #define __GNUG__ 7 152 | #define __LONG_LONG_MAX__ 0x7fffffffffffffffLL 153 | #define __SIZEOF_SIZE_T__ 8 154 | #define __cpp_rvalue_reference 200610 155 | #define __cpp_nsdmi 200809 156 | #define __FLT64X_MIN_EXP__ (-16381) 157 | #define __SIZEOF_WINT_T__ 2 158 | #define __LONG_LONG_WIDTH__ 64 159 | #define __cpp_initializer_lists 200806 160 | #define __FLT32_MAX_EXP__ 128 161 | #define __cpp_hex_float 201603 162 | #define __GCC_HAVE_DWARF2_CFI_ASM 1 163 | #define __GXX_ABI_VERSION 1011 164 | #define __FLT128_HAS_INFINITY__ 1 165 | #define __FLT_MIN_EXP__ (-125) 166 | #define __cpp_lambdas 200907 167 | #define __FLT64X_HAS_QUIET_NAN__ 1 168 | #define __INT_FAST64_TYPE__ long long int 169 | #define __FLT64_DENORM_MIN__ 4.94065645841246544176568792868221372e-324F64 170 | #define __DBL_MIN__ double(2.22507385850720138309023271733240406e-308L) 171 | #define __FLT32X_EPSILON__ 2.22044604925031308084726333618164062e-16F32x 172 | #define __DECIMAL_BID_FORMAT__ 1 173 | #define __GXX_TYPEINFO_EQUALITY_INLINE 0 174 | #define __FLT64_MIN_10_EXP__ (-307) 175 | #define __FLT64X_DECIMAL_DIG__ 21 176 | #define __DEC128_MIN__ 1E-6143DL 177 | #define __REGISTER_PREFIX__ 178 | #define __UINT16_MAX__ 0xffff 179 | #define __DBL_HAS_DENORM__ 1 180 | #define __cdecl __attribute__((__cdecl__)) 181 | #define __FLT32_MIN__ 1.17549435082228750796873653722224568e-38F32 182 | #define __UINT8_TYPE__ unsigned char 183 | #define __NO_INLINE__ 1 184 | #define __FLT_MANT_DIG__ 24 185 | #define __LDBL_DECIMAL_DIG__ 21 186 | #define __VERSION__ "7.3.0" 187 | #define __UINT64_C(c) c ## ULL 188 | #define __cpp_unicode_characters 200704 189 | #define __cpp_decltype_auto 201304 190 | #define __GCC_ATOMIC_INT_LOCK_FREE 2 191 | #define __FLT128_MAX_EXP__ 16384 192 | #define __FLT32_MANT_DIG__ 24 193 | #define __FLOAT_WORD_ORDER__ __ORDER_LITTLE_ENDIAN__ 194 | #define __FLT128_HAS_DENORM__ 1 195 | #define __FLT128_DIG__ 33 196 | #define __SCHAR_WIDTH__ 8 197 | #define __INT32_C(c) c 198 | #define __DEC64_EPSILON__ 1E-15DD 199 | #define __ORDER_PDP_ENDIAN__ 3412 200 | #define __DEC128_MIN_EXP__ (-6142) 201 | #define __FLT32_MAX_10_EXP__ 38 202 | #define __INT_FAST32_TYPE__ int 203 | #define __UINT_LEAST16_TYPE__ short unsigned int 204 | #define __FLT64X_HAS_INFINITY__ 1 205 | #define __INT16_MAX__ 0x7fff 206 | #define __cpp_rtti 199711 207 | #define __SIZE_TYPE__ long long unsigned int 208 | #define __UINT64_MAX__ 0xffffffffffffffffULL 209 | #define __FLT64X_DIG__ 18 210 | #define __INT8_TYPE__ signed char 211 | #define __cpp_digit_separators 201309 212 | #define __GCC_ASM_FLAG_OUTPUTS__ 1 213 | #define __FLT_RADIX__ 2 214 | #define __INT_LEAST16_TYPE__ short int 215 | #define __LDBL_EPSILON__ 1.08420217248550443400745280086994171e-19L 216 | #define __UINTMAX_C(c) c ## ULL 217 | #define __GLIBCXX_BITSIZE_INT_N_0 128 218 | #define __SEH__ 1 219 | #define __SIG_ATOMIC_MAX__ 0x7fffffff 220 | #define __GCC_ATOMIC_WCHAR_T_LOCK_FREE 2 221 | #define __cpp_sized_deallocation 201309 222 | #define __SIZEOF_PTRDIFF_T__ 8 223 | #define __FLT32X_MANT_DIG__ 53 224 | #define __x86_64__ 1 225 | #define __FLT32X_MIN_EXP__ (-1021) 226 | #define __DEC32_SUBNORMAL_MIN__ 0.000001E-95DF 227 | #define __MSVCRT__ 1 228 | #define __INT_FAST16_MAX__ 0x7fff 229 | #define __FLT64_DIG__ 15 230 | #define __UINT_FAST32_MAX__ 0xffffffffU 231 | #define __UINT_LEAST64_TYPE__ long long unsigned int 232 | #define __FLT_HAS_QUIET_NAN__ 1 233 | #define __FLT_MAX_10_EXP__ 38 234 | #define __LONG_MAX__ 0x7fffffffL 235 | #define __FLT64X_HAS_DENORM__ 1 236 | #define __DEC128_SUBNORMAL_MIN__ 0.000000000000000000000000000000001E-6143DL 237 | #define __FLT_HAS_INFINITY__ 1 238 | #define __cpp_unicode_literals 200710 239 | #define __UINT_FAST16_TYPE__ short unsigned int 240 | #define __DEC64_MAX__ 9.999999999999999E384DD 241 | #define __INT_FAST32_WIDTH__ 32 242 | #define __CHAR16_TYPE__ short unsigned int 243 | #define __PRAGMA_REDEFINE_EXTNAME 1 244 | #define __SIZE_WIDTH__ 64 245 | #define __SEG_FS 1 246 | #define __INT_LEAST16_MAX__ 0x7fff 247 | #define __DEC64_MANT_DIG__ 16 248 | #define __UINT_LEAST32_MAX__ 0xffffffffU 249 | #define __SEG_GS 1 250 | #define __FLT32_DENORM_MIN__ 1.40129846432481707092372958328991613e-45F32 251 | #define __GCC_ATOMIC_LONG_LOCK_FREE 2 252 | #define __SIG_ATOMIC_WIDTH__ 32 253 | #define __INT_LEAST64_TYPE__ long long int 254 | #define __INT16_TYPE__ short int 255 | #define __INT_LEAST8_TYPE__ signed char 256 | #define __DEC32_MAX_EXP__ 97 257 | #define __INT_FAST8_MAX__ 0x7f 258 | #define __FLT128_MAX__ 1.18973149535723176508575932662800702e+4932F128 259 | #define __INTPTR_MAX__ 0x7fffffffffffffffLL 260 | #define __GXX_MERGED_TYPEINFO_NAMES 0 261 | #define __cpp_range_based_for 200907 262 | #define __FLT64_HAS_QUIET_NAN__ 1 263 | #define __stdcall __attribute__((__stdcall__)) 264 | #define __FLT32_MIN_10_EXP__ (-37) 265 | #define __SSE2__ 1 266 | #define __EXCEPTIONS 1 267 | #define __LDBL_MANT_DIG__ 64 268 | #define __DBL_HAS_QUIET_NAN__ 1 269 | #define __FLT64_HAS_INFINITY__ 1 270 | #define __FLT64X_MAX__ 1.18973149535723176502126385303097021e+4932F64x 271 | #define __SIG_ATOMIC_MIN__ (-__SIG_ATOMIC_MAX__ - 1) 272 | #define __cpp_return_type_deduction 201304 273 | #define __INTPTR_TYPE__ long long int 274 | #define __UINT16_TYPE__ short unsigned int 275 | #define __WCHAR_TYPE__ short unsigned int 276 | #define __SIZEOF_FLOAT__ 4 277 | #define __pic__ 1 278 | #define __UINTPTR_MAX__ 0xffffffffffffffffULL 279 | #define __INT_FAST64_WIDTH__ 64 280 | #define __DEC64_MIN_EXP__ (-382) 281 | #define __cpp_decltype 200707 282 | #define __FLT32_DECIMAL_DIG__ 9 283 | #define __INT_FAST64_MAX__ 0x7fffffffffffffffLL 284 | #define __GCC_ATOMIC_TEST_AND_SET_TRUEVAL 1 285 | #define __FLT_DIG__ 6 286 | #define __FLT64X_MAX_EXP__ 16384 287 | #define __UINT_FAST64_TYPE__ long long unsigned int 288 | #define __INT_MAX__ 0x7fffffff 289 | #define __amd64__ 1 290 | #define WIN32 1 291 | #define __nocona 1 292 | #define __code_model_medium__ 1 293 | #define __INT64_TYPE__ long long int 294 | #define __FLT_MAX_EXP__ 128 295 | #define WIN64 1 296 | #define __ORDER_BIG_ENDIAN__ 4321 297 | #define __DBL_MANT_DIG__ 53 298 | #define __cpp_inheriting_constructors 201511 299 | #define __SIZEOF_FLOAT128__ 16 300 | #define __INT_LEAST64_MAX__ 0x7fffffffffffffffLL 301 | #define __DEC64_MIN__ 1E-383DD 302 | #define __WINT_TYPE__ short unsigned int 303 | #define __UINT_LEAST32_TYPE__ unsigned int 304 | #define __SIZEOF_SHORT__ 2 305 | #define __SSE__ 1 306 | #define __LDBL_MIN_EXP__ (-16381) 307 | #define __FLT64_MAX__ 1.79769313486231570814527423731704357e+308F64 308 | #define __WINT_WIDTH__ 16 309 | #define __INT_LEAST8_MAX__ 0x7f 310 | #define __FLT32X_MAX_10_EXP__ 308 311 | #define __SIZEOF_INT128__ 16 312 | #define __WCHAR_UNSIGNED__ 1 313 | #define __LDBL_MAX_10_EXP__ 4932 314 | #define __ATOMIC_RELAXED 0 315 | #define __DBL_EPSILON__ double(2.22044604925031308084726333618164062e-16L) 316 | #define __thiscall __attribute__((__thiscall__)) 317 | #define __FLT128_MIN__ 3.36210314311209350626267781732175260e-4932F128 318 | #define __UINT8_C(c) c 319 | #define __FLT64_MAX_EXP__ 1024 320 | #define __INT_LEAST32_TYPE__ int 321 | #define __SIZEOF_WCHAR_T__ 2 322 | #define __FLT128_HAS_QUIET_NAN__ 1 323 | #define __INT_FAST8_TYPE__ signed char 324 | #define __fastcall __attribute__((__fastcall__)) 325 | #define __FLT64X_MIN__ 3.36210314311209350626267781732175260e-4932F64x 326 | #define __GNUC_STDC_INLINE__ 1 327 | #define __FLT64_HAS_DENORM__ 1 328 | #define __FLT32_EPSILON__ 1.19209289550781250000000000000000000e-7F32 329 | #define __DBL_DECIMAL_DIG__ 17 330 | #define __STDC_UTF_32__ 1 331 | #define __INT_FAST8_WIDTH__ 8 332 | #define __FXSR__ 1 333 | #define __DEC_EVAL_METHOD__ 2 334 | #define __FLT32X_MAX__ 1.79769313486231570814527423731704357e+308F32x 335 | #define __MINGW64__ 1 336 | #define __cpp_runtime_arrays 198712 337 | #define __UINT64_TYPE__ long long unsigned int 338 | #define __UINT32_C(c) c ## U 339 | #define __INTMAX_MAX__ 0x7fffffffffffffffLL 340 | #define __cpp_alias_templates 200704 341 | #define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__ 342 | #define WINNT 1 343 | #define __FLT_DENORM_MIN__ 1.40129846432481707092372958328991613e-45F 344 | #define __INT8_MAX__ 0x7f 345 | #define __LONG_WIDTH__ 32 346 | #define __PIC__ 1 347 | #define __UINT_FAST32_TYPE__ unsigned int 348 | #define __CHAR32_TYPE__ unsigned int 349 | #define __FLT_MAX__ 3.40282346638528859811704183484516925e+38F 350 | #define __cpp_constexpr 201304 351 | #define __INT32_TYPE__ int 352 | #define __SIZEOF_DOUBLE__ 8 353 | #define __cpp_exceptions 199711 354 | #define __FLT_MIN_10_EXP__ (-37) 355 | #define __FLT64_MIN__ 2.22507385850720138309023271733240406e-308F64 356 | #define __INT_LEAST32_WIDTH__ 32 357 | #define __INTMAX_TYPE__ long long int 358 | #define _INTEGRAL_MAX_BITS 64 359 | #define __DEC128_MAX_EXP__ 6145 360 | #define __FLT32X_HAS_QUIET_NAN__ 1 361 | #define __ATOMIC_CONSUME 1 362 | #define __nocona__ 1 363 | #define __GNUC_MINOR__ 3 364 | #define __GLIBCXX_TYPE_INT_N_0 __int128 365 | #define __INT_FAST16_WIDTH__ 16 366 | #define __UINTMAX_MAX__ 0xffffffffffffffffULL 367 | #define __DEC32_MANT_DIG__ 7 368 | #define __FLT32X_DENORM_MIN__ 4.94065645841246544176568792868221372e-324F32x 369 | #define __DBL_MAX_10_EXP__ 308 370 | #define __LDBL_DENORM_MIN__ 3.64519953188247460252840593361941982e-4951L 371 | #define __INT16_C(c) c 372 | #define __cpp_generic_lambdas 201304 373 | #define __STDC__ 1 374 | #define __FLT32X_DIG__ 15 375 | #define __PTRDIFF_TYPE__ long long int 376 | #define __ATOMIC_SEQ_CST 5 377 | #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_16 1 378 | #define __UINT32_TYPE__ unsigned int 379 | #define __FLT32X_MIN_10_EXP__ (-307) 380 | #define __UINTPTR_TYPE__ long long unsigned int 381 | #define __DEC64_SUBNORMAL_MIN__ 0.000000000000001E-383DD 382 | #define __DEC128_MANT_DIG__ 34 383 | #define __LDBL_MIN_10_EXP__ (-4931) 384 | #define __FLT128_EPSILON__ 1.92592994438723585305597794258492732e-34F128 385 | #define __SSE_MATH__ 1 386 | #define __SIZEOF_LONG_LONG__ 8 387 | #define __cpp_user_defined_literals 200809 388 | #define __FLT128_DECIMAL_DIG__ 36 389 | #define __GCC_ATOMIC_LLONG_LOCK_FREE 2 390 | #define __FLT32X_MIN__ 2.22507385850720138309023271733240406e-308F32x 391 | #define __LDBL_DIG__ 18 392 | #define __FLT_DECIMAL_DIG__ 9 393 | #define __UINT_FAST16_MAX__ 0xffff 394 | #define __GCC_ATOMIC_SHORT_LOCK_FREE 2 395 | #define __INT_LEAST64_WIDTH__ 64 396 | #define __SSE3__ 1 397 | #define __UINT_FAST8_TYPE__ unsigned char 398 | #define __WIN64__ 1 399 | #define __cpp_init_captures 201304 400 | #define __ATOMIC_ACQ_REL 4 401 | #define __ATOMIC_RELEASE 3 402 | #define __declspec(x) __attribute__((x)) 403 | -------------------------------------------------------------------------------- /Qt_Linguist _Demo/build-language_demo-Desktop_Qt_5_12_1_MinGW_64_bit-Debug/ui_mainwindow.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************** 2 | ** Form generated from reading UI file 'mainwindow.ui' 3 | ** 4 | ** Created by: Qt User Interface Compiler version 5.12.1 5 | ** 6 | ** WARNING! All changes made in this file will be lost when recompiling UI file! 7 | ********************************************************************************/ 8 | 9 | #ifndef UI_MAINWINDOW_H 10 | #define UI_MAINWINDOW_H 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | QT_BEGIN_NAMESPACE 25 | 26 | class Ui_MainWindow 27 | { 28 | public: 29 | QAction *actiona_chinese; 30 | QAction *actionb_English; 31 | QWidget *centralWidget; 32 | QCalendarWidget *calendarWidget; 33 | QLabel *label; 34 | QMenuBar *menuBar; 35 | QMenu *menua; 36 | QToolBar *mainToolBar; 37 | QStatusBar *statusBar; 38 | 39 | void setupUi(QMainWindow *MainWindow) 40 | { 41 | if (MainWindow->objectName().isEmpty()) 42 | MainWindow->setObjectName(QString::fromUtf8("MainWindow")); 43 | MainWindow->resize(407, 318); 44 | actiona_chinese = new QAction(MainWindow); 45 | actiona_chinese->setObjectName(QString::fromUtf8("actiona_chinese")); 46 | actionb_English = new QAction(MainWindow); 47 | actionb_English->setObjectName(QString::fromUtf8("actionb_English")); 48 | centralWidget = new QWidget(MainWindow); 49 | centralWidget->setObjectName(QString::fromUtf8("centralWidget")); 50 | calendarWidget = new QCalendarWidget(centralWidget); 51 | calendarWidget->setObjectName(QString::fromUtf8("calendarWidget")); 52 | calendarWidget->setGeometry(QRect(70, 10, 248, 197)); 53 | label = new QLabel(centralWidget); 54 | label->setObjectName(QString::fromUtf8("label")); 55 | label->setGeometry(QRect(30, 210, 331, 41)); 56 | QFont font; 57 | font.setFamily(QString::fromUtf8("\345\215\216\346\226\207\346\226\260\351\255\217")); 58 | font.setPointSize(15); 59 | label->setFont(font); 60 | label->setLineWidth(1); 61 | MainWindow->setCentralWidget(centralWidget); 62 | menuBar = new QMenuBar(MainWindow); 63 | menuBar->setObjectName(QString::fromUtf8("menuBar")); 64 | menuBar->setGeometry(QRect(0, 0, 407, 23)); 65 | menua = new QMenu(menuBar); 66 | menua->setObjectName(QString::fromUtf8("menua")); 67 | MainWindow->setMenuBar(menuBar); 68 | mainToolBar = new QToolBar(MainWindow); 69 | mainToolBar->setObjectName(QString::fromUtf8("mainToolBar")); 70 | MainWindow->addToolBar(Qt::TopToolBarArea, mainToolBar); 71 | statusBar = new QStatusBar(MainWindow); 72 | statusBar->setObjectName(QString::fromUtf8("statusBar")); 73 | MainWindow->setStatusBar(statusBar); 74 | 75 | menuBar->addAction(menua->menuAction()); 76 | menua->addAction(actiona_chinese); 77 | menua->addAction(actionb_English); 78 | 79 | retranslateUi(MainWindow); 80 | 81 | QMetaObject::connectSlotsByName(MainWindow); 82 | } // setupUi 83 | 84 | void retranslateUi(QMainWindow *MainWindow) 85 | { 86 | MainWindow->setWindowTitle(QApplication::translate("MainWindow", "\347\254\254\344\270\200\344\270\252qt\347\250\213\345\272\217", nullptr)); 87 | actiona_chinese->setText(QApplication::translate("MainWindow", "\344\270\255\346\226\207", nullptr)); 88 | actionb_English->setText(QApplication::translate("MainWindow", "English", nullptr)); 89 | label->setText(QApplication::translate("MainWindow", "\346\254\242\350\277\216\345\205\263\346\263\250\345\276\256\344\277\241\345\205\254\344\274\227\345\217\267\343\200\220\347\274\226\347\250\213\345\255\246\344\271\240\345\237\272\345\234\260\343\200\221", nullptr)); 90 | menua->setTitle(QApplication::translate("MainWindow", "\350\257\255\350\250\200", nullptr)); 91 | } // retranslateUi 92 | 93 | }; 94 | 95 | namespace Ui { 96 | class MainWindow: public Ui_MainWindow {}; 97 | } // namespace Ui 98 | 99 | QT_END_NAMESPACE 100 | 101 | #endif // UI_MAINWINDOW_H 102 | -------------------------------------------------------------------------------- /Qt_Linguist _Demo/language/Translate_CN.qm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/Qt_Linguist _Demo/language/Translate_CN.qm -------------------------------------------------------------------------------- /Qt_Linguist _Demo/language/Translate_CN.ts: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | MainWindow 6 | 7 | 8 | 第一个qt程序 9 | 10 | 11 | 12 | 13 | 欢迎关注微信公众号【编程学习基地】 14 | 15 | 16 | 17 | 18 | 语言 19 | 20 | 21 | 22 | 23 | 中文 24 | 25 | 26 | 27 | 28 | English 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /Qt_Linguist _Demo/language/Translate_EN.qm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/Qt_Linguist _Demo/language/Translate_EN.qm -------------------------------------------------------------------------------- /Qt_Linguist _Demo/language/Translate_EN.ts: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | MainWindow 6 | 7 | MainWindow 8 | MainWindow 9 | 10 | 11 | 12 | 第一个qt程序 13 | My First Window 14 | 15 | 16 | 17 | 欢迎关注微信公众号【编程学习基地】 18 | Thanks for your attention to LearnBase 19 | 20 | 21 | 22 | 语言 23 | Language 24 | 25 | 26 | 27 | 中文 28 | Chinese 29 | 30 | 31 | 32 | English 33 | English 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /Qt_Linguist _Demo/language/language_demo.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2020-05-07T18:38:16 4 | # 5 | #------------------------------------------------- 6 | 7 | QT += core gui 8 | 9 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 10 | 11 | TARGET = language_demo 12 | TEMPLATE = app 13 | 14 | TRANSLATIONS = Translate_EN.ts \ 15 | Translate_CN.ts 16 | # The following define makes your compiler emit warnings if you use 17 | # any feature of Qt which has been marked as deprecated (the exact warnings 18 | # depend on your compiler). Please consult the documentation of the 19 | # deprecated API in order to know how to port your code away from it. 20 | DEFINES += QT_DEPRECATED_WARNINGS 21 | 22 | # You can also make your code fail to compile if you use deprecated APIs. 23 | # In order to do so, uncomment the following line. 24 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 25 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 26 | 27 | 28 | SOURCES += \ 29 | main.cpp \ 30 | mainwindow.cpp 31 | 32 | HEADERS += \ 33 | mainwindow.h 34 | 35 | FORMS += \ 36 | mainwindow.ui 37 | -------------------------------------------------------------------------------- /Qt_Linguist _Demo/language/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication a(argc, argv); 7 | MainWindow w; 8 | w.show(); 9 | 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /Qt_Linguist _Demo/language/mainwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include "ui_mainwindow.h" 3 | 4 | MainWindow::MainWindow(QWidget *parent) : 5 | QMainWindow(parent), 6 | ui(new Ui::MainWindow) 7 | { 8 | ui->setupUi(this); 9 | m_Translator = new QTranslator(this); 10 | } 11 | 12 | MainWindow::~MainWindow() 13 | { 14 | delete ui; 15 | } 16 | 17 | void MainWindow::on_actiona_chinese_triggered() 18 | { 19 | m_Translator->load("Translate_CN.qm"); 20 | ui->calendarWidget->setLocale(QLocale::Chinese); 21 | qApp->installTranslator(m_Translator); 22 | ui->retranslateUi(this); 23 | } 24 | 25 | void MainWindow::on_actionb_English_triggered() 26 | { 27 | m_Translator->load("Translate_EN.qm"); 28 | qApp->installTranslator(m_Translator); 29 | 30 | ui->calendarWidget->setLocale(QLocale::C); 31 | 32 | ui->retranslateUi(this); 33 | } 34 | -------------------------------------------------------------------------------- /Qt_Linguist _Demo/language/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | #include 6 | 7 | namespace Ui { 8 | class MainWindow; 9 | } 10 | 11 | class MainWindow : public QMainWindow 12 | { 13 | Q_OBJECT 14 | 15 | public: 16 | explicit MainWindow(QWidget *parent = 0); 17 | ~MainWindow(); 18 | 19 | private slots: 20 | void on_actiona_chinese_triggered(); 21 | 22 | void on_actionb_English_triggered(); 23 | 24 | private: 25 | Ui::MainWindow *ui; 26 | QTranslator *m_Translator; 27 | }; 28 | 29 | #endif // MAINWINDOW_H 30 | -------------------------------------------------------------------------------- /Qt_Linguist _Demo/language/mainwindow.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 407 10 | 318 11 | 12 | 13 | 14 | 第一个qt程序 15 | 16 | 17 | 18 | 19 | 20 | 70 21 | 10 22 | 248 23 | 197 24 | 25 | 26 | 27 | 28 | 29 | 30 | 30 31 | 210 32 | 331 33 | 41 34 | 35 | 36 | 37 | 38 | 华文新魏 39 | 15 40 | 41 | 42 | 43 | 1 44 | 45 | 46 | 欢迎关注微信公众号【编程学习基地】 47 | 48 | 49 | 50 | 51 | 52 | 53 | 0 54 | 0 55 | 407 56 | 23 57 | 58 | 59 | 60 | 61 | 语言 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | TopToolBarArea 71 | 72 | 73 | false 74 | 75 | 76 | 77 | 78 | 79 | 中文 80 | 81 | 82 | 83 | 84 | English 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /SrceenWidget/SrceenWidget.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2020-07-28T00:41:28 4 | # 5 | #------------------------------------------------- 6 | 7 | QT += core gui 8 | 9 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 10 | 11 | TARGET = SrceenWidget 12 | TEMPLATE = app 13 | 14 | # The following define makes your compiler emit warnings if you use 15 | # any feature of Qt which has been marked as deprecated (the exact warnings 16 | # depend on your compiler). Please consult the documentation of the 17 | # deprecated API in order to know how to port your code away from it. 18 | DEFINES += QT_DEPRECATED_WARNINGS 19 | 20 | # You can also make your code fail to compile if you use deprecated APIs. 21 | # In order to do so, uncomment the following line. 22 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 23 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 24 | 25 | CONFIG += c++11 26 | 27 | SOURCES += \ 28 | main.cpp \ 29 | widget.cpp \ 30 | srceen.cpp 31 | 32 | HEADERS += \ 33 | widget.h \ 34 | srceen.h 35 | 36 | FORMS += \ 37 | widget.ui 38 | 39 | # Default rules for deployment. 40 | qnx: target.path = /tmp/$${TARGET}/bin 41 | else: unix:!android: target.path = /opt/$${TARGET}/bin 42 | !isEmpty(target.path): INSTALLS += target 43 | 44 | RESOURCES += \ 45 | src.qrc 46 | -------------------------------------------------------------------------------- /SrceenWidget/main.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication a(argc, argv); 7 | Widget w; 8 | w.show(); 9 | 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /SrceenWidget/src.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | src/apple.ico 4 | src/screenshot.png 5 | 6 | 7 | -------------------------------------------------------------------------------- /SrceenWidget/src/apple.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/SrceenWidget/src/apple.ico -------------------------------------------------------------------------------- /SrceenWidget/src/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/SrceenWidget/src/screenshot.png -------------------------------------------------------------------------------- /SrceenWidget/srceen.cpp: -------------------------------------------------------------------------------- 1 | #include "srceen.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | Srceen::Srceen(QWidget *parent) : QWidget(parent) 11 | { 12 | this->setWindowFlags(Qt::FramelessWindowHint); //去掉标题栏 13 | this->setAttribute(Qt::WA_TranslucentBackground); //设置背景透明 14 | SrceenValInit(); 15 | } 16 | 17 | void Srceen::paintEvent(QPaintEvent *) 18 | { 19 | QPixmap pix(originalPixmap.width(), originalPixmap.height()); 20 | pix.fill((QColor(0, 0, 0, 120))); //阴影颜色设置; 21 | QPainter painter(this); 22 | 23 | QPen pen; 24 | pen.setColor(Qt::green); 25 | pen.setWidth(1); 26 | painter.setPen(pen); 27 | 28 | QFont font; 29 | font.setPointSize(12); 30 | painter.setFont(font); 31 | 32 | painter.drawPixmap(0,0,originalPixmap); 33 | painter.drawPixmap(0,0,pix); //画一层阴影 34 | 35 | /* 绘制截图区域 */ 36 | if(rectangle.height()!=0||rectangle.width()!=0) 37 | { 38 | if(rectangle.height()<0 && rectangle.width()>0) 39 | { 40 | //绘制用户截图区域 鼠标在起点的右上方 41 | screenRect.setRect(rectangle.x(),rectangle.y()+rectangle.height(),rectangle.width(),qAbs(rectangle.height())); 42 | } 43 | else if (rectangle.width()<0 && rectangle.height()>0) { 44 | //绘制用户截图区域 鼠标在起点的左下方 45 | screenRect.setRect(rectangle.x() + rectangle.width(),rectangle.y(),qAbs(rectangle.width()),rectangle.height()); 46 | } 47 | else if (rectangle.height()< 0 && rectangle.width()<0) { 48 | //绘制用户截图区域 鼠标在起点的左上方 49 | screenRect.setRect(rectangle.x()+rectangle.width(),rectangle.y()+rectangle.height(),qAbs(rectangle.width()),qAbs(rectangle.height())); 50 | } 51 | else if(rectangle.height()> 0 && rectangle.width()>0){ 52 | //绘制用户截图区域 鼠标在起点的右下方 53 | screenRect.setRect(rectangle.x(),rectangle.y(),rectangle.width(),rectangle.height()); 54 | } 55 | painter.drawPixmap(screenRect.x(),screenRect.y(),originalPixmap.copy(screenRect)); 56 | painter.drawRect(rectangle); 57 | 58 | pen.setColor(Qt::white); 59 | painter.setPen(pen); 60 | painter.drawText(screenRect.x() + 2, screenRect.y() - 8, QString("%1 x %2").arg(screenRect.width()).arg(screenRect.height())); 61 | 62 | /*放大图*/ 63 | QPixmap endPointImage = originalPixmap.copy(mousePos.x() - 25 64 | ,mousePos.y() - 25,50,50).scaled(100, 100); 65 | //放大矩形区域 66 | enlargeRect.setRect(mousePos.x() + 32,mousePos.y() + 22,100,100); 67 | //绘制放大矩形区域 68 | painter.drawPixmap(enlargeRect.x(),enlargeRect.y(), endPointImage); 69 | //绘制十字坐标 70 | pen.setColor(Qt::green); 71 | painter.setPen(pen); 72 | //横线 73 | painter.drawLine(enlargeRect.x(),enlargeRect.y() + enlargeRect.height()/2, 74 | enlargeRect.x() + enlargeRect.width(),enlargeRect.y() + enlargeRect.height()/2); 75 | //竖线 76 | painter.drawLine(enlargeRect.x() + enlargeRect.width()/2,enlargeRect.y(), 77 | enlargeRect.x() + enlargeRect.width()/2,enlargeRect.y() + enlargeRect.height()); 78 | //方块 79 | painter.drawRect(enlargeRect); 80 | //文字 81 | pen.setColor(Qt::white); 82 | painter.setPen(pen); 83 | painter.drawText(enlargeRect.x(), enlargeRect.y() + enlargeRect.height()+ 16, QString("POS:(%1,%2)").arg(enlargeRect.x()).arg(enlargeRect.y())); 84 | 85 | } 86 | else { 87 | painter.drawRect(originalPixmap.rect()); //给全屏边框绘制绿色矩形框 88 | } 89 | } 90 | 91 | void Srceen::mousePressEvent(QMouseEvent *event) 92 | { 93 | //鼠标左键按下,设置截图起点 94 | if (event->button() == Qt::LeftButton) 95 | { 96 | rectangle.setRect(event->x(),event->y(),0,0); 97 | } 98 | } 99 | 100 | void Srceen::mouseReleaseEvent(QMouseEvent *event) 101 | { 102 | Q_UNUSED(event) 103 | } 104 | 105 | void Srceen::mouseMoveEvent(QMouseEvent *event) 106 | { 107 | mousePos.setX(event->x()); 108 | mousePos.setY(event->y()); 109 | if(rectangle.x()!=-1||rectangle.y()!=-1) 110 | { 111 | rectangle.setHeight(event->y()-rectangle.y()); 112 | rectangle.setWidth(event->x()-rectangle.x()); 113 | } 114 | this->update(); 115 | } 116 | 117 | //右键菜单 118 | void Srceen::contextMenuEvent(QContextMenuEvent *event) 119 | { 120 | Q_UNUSED(event) 121 | RightButtonMenu->clear(); 122 | RightButtonMenu->addAction(saveSreenShot); 123 | RightButtonMenu->addAction(saveCopyAs); 124 | RightButtonMenu->addSeparator(); //分割线 125 | RightButtonMenu->addAction(quitSreenShot); 126 | RightButtonMenu->exec(QCursor::pos()); //在当前鼠标处堵住 127 | } 128 | 129 | //获取桌面截图 130 | void Srceen::GetWindowSrceen() 131 | { 132 | screen = QGuiApplication::primaryScreen(); //获取屏幕图像 133 | originalPixmap = screen->grabWindow(0); 134 | rectangle.setRect(0,0,0,0); 135 | } 136 | 137 | //保存截图 138 | void Srceen::SaveSrceenShot() 139 | { 140 | clip = QApplication::clipboard(); 141 | clip->setPixmap(originalPixmap.copy(screenRect)); //保存到粘贴板 142 | this->hide(); 143 | rectangle.setRect(0,0,0,0); 144 | } 145 | 146 | //图片另存为 147 | void Srceen::SaveCopyAs() 148 | { 149 | QDateTime current_time = QDateTime::currentDateTime(); 150 | //显示时间,格式为:年-月-日 151 | QString StrCurrentTime = current_time.toString("yyyy-MM-dd"); 152 | 153 | QString fileName = QFileDialog::getSaveFileName(this,"保存文件",StrCurrentTime, 154 | tr("Image Files (*.png);;Image Files (*.jpg);;Image Files (*.bmp)")); 155 | if(!fileName.isNull()) 156 | { 157 | originalPixmap.copy(screenRect).save(fileName); 158 | this->hide(); 159 | } 160 | rectangle.setRect(0,0,0,0); 161 | } 162 | 163 | void Srceen::MenuClose() 164 | { 165 | rectangle.setRect(0,0,0,0); 166 | this->close(); 167 | } 168 | 169 | void Srceen::SrceenValInit() 170 | { 171 | saveSreenShot = new QAction(tr("保存截图"), this); 172 | connect(saveSreenShot, SIGNAL(triggered()), this, SLOT(SaveSrceenShot())); 173 | quitSreenShot = new QAction(tr("退出截图"), this); 174 | connect(quitSreenShot, SIGNAL(triggered()), this, SLOT(MenuClose())); 175 | saveCopyAs = new QAction(tr("另存为"),this); 176 | connect(saveCopyAs, SIGNAL(triggered()), this, SLOT(SaveCopyAs())); 177 | RightButtonMenu = new QMenu(this); 178 | } 179 | -------------------------------------------------------------------------------- /SrceenWidget/srceen.h: -------------------------------------------------------------------------------- 1 | #ifndef SRCEEN_H 2 | #define SRCEEN_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | class Srceen : public QWidget 12 | { 13 | Q_OBJECT 14 | public: 15 | explicit Srceen(QWidget *parent = nullptr); 16 | protected: 17 | virtual void paintEvent(QPaintEvent *); 18 | 19 | virtual void mousePressEvent(QMouseEvent *event); 20 | virtual void mouseReleaseEvent(QMouseEvent *event); 21 | virtual void mouseMoveEvent(QMouseEvent *event); 22 | virtual void contextMenuEvent(QContextMenuEvent *event); //右键菜单 23 | public slots: 24 | void GetWindowSrceen(); //获取桌面全屏 25 | void SaveSrceenShot(); //保存截屏 26 | void SaveCopyAs(); 27 | void MenuClose(); 28 | private: 29 | void SrceenValInit(); 30 | private: 31 | QScreen *screen; //桌面截图 32 | QPixmap originalPixmap; //截图 33 | QRect rectangle; //截图矩形 34 | QRect screenRect; //屏幕截图矩形 35 | QRect enlargeRect; //放大矩形 36 | QPoint mousePos; //鼠标坐标 37 | 38 | QClipboard * clip; //剪切板 39 | 40 | QMenu *RightButtonMenu; //右键菜单 41 | QAction *saveSreenShot; //保存到粘贴板 42 | QAction *saveCopyAs; //另存为 43 | QAction *quitSreenShot; //退出截图 44 | }; 45 | 46 | #endif // SRCEEN_H 47 | -------------------------------------------------------------------------------- /SrceenWidget/widget.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | #include "ui_widget.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | Widget::Widget(QWidget *parent) : 9 | QWidget(parent), 10 | ui(new Ui::Widget) 11 | { 12 | ui->setupUi(this); 13 | WidgetValInit(); 14 | } 15 | 16 | Widget::~Widget() 17 | { 18 | delete ui; 19 | } 20 | 21 | void Widget::on_pushButton_clicked() 22 | { 23 | if(isHide) 24 | { 25 | this->hide(); 26 | Sleep(200); 27 | } 28 | emit SrceenBegin(); 29 | srceenWidget->show(); 30 | srceenWidget->showFullScreen(); 31 | } 32 | 33 | void Widget::slot_RadioButton_checket(int id) 34 | { 35 | QRadioButton* temp = (QRadioButton*)radioGroup->button(id); 36 | switch(id) 37 | { 38 | case 0: 39 | if(temp->isChecked()) 40 | { 41 | isHide = true; 42 | } 43 | else { 44 | isHide = false; 45 | } 46 | break; 47 | case 1: 48 | break; 49 | } 50 | } 51 | 52 | void Widget::WidgetValInit() 53 | { 54 | quitAction = new QAction(tr("退出"), this); 55 | connect(quitAction, SIGNAL(triggered()), this, SLOT(close())); 56 | 57 | screenShotAction = new QAction(tr("截图"), this); 58 | screenShotAction->setIcon(QIcon(":/src/screenshot.png")); 59 | connect(screenShotAction, SIGNAL(triggered()), this, SLOT(on_pushButton_clicked())); 60 | 61 | trayIconMenu = new QMenu(this); 62 | trayIconMenu->addAction(screenShotAction); 63 | trayIconMenu->addAction(quitAction); 64 | trayIcon = new QSystemTrayIcon(this); 65 | 66 | /*将之前加载的菜单设置为系统托盘菜单*/ 67 | trayIcon->setContextMenu(trayIconMenu); 68 | /* 设置托盘显示的图标。 */ 69 | trayIcon->setIcon(QIcon(":/src/apple.ico")); 70 | setWindowIcon(QIcon(":/src/apple.ico")); 71 | /* 设置鼠标移动到托盘图标显示的文本。 */ 72 | trayIcon->setToolTip("截图"); 73 | /*截图*/ 74 | srceenWidget = new Srceen; 75 | connect(this,SIGNAL(SrceenBegin()),srceenWidget,SLOT(GetWindowSrceen())); 76 | 77 | radioGroup = new QButtonGroup(this); 78 | radioGroup->setExclusive(false); //重点 设置不互斥 79 | radioGroup->addButton(ui->radioButton,0); 80 | radioGroup->addButton(ui->anotherRadioButton,1); 81 | connect(radioGroup, SIGNAL(buttonClicked(int)), this,SLOT(slot_RadioButton_checket(int))); 82 | isHide = true; 83 | } 84 | -------------------------------------------------------------------------------- /SrceenWidget/widget.h: -------------------------------------------------------------------------------- 1 | #ifndef WIDGET_H 2 | #define WIDGET_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "srceen.h" 9 | namespace Ui { 10 | class Widget; 11 | } 12 | 13 | class Widget : public QWidget 14 | { 15 | Q_OBJECT 16 | 17 | public: 18 | explicit Widget(QWidget *parent = nullptr); 19 | ~Widget(); 20 | signals: 21 | void SrceenBegin(); //给srceenWidget发送开始截图信号 22 | private slots: 23 | void on_pushButton_clicked(); 24 | private slots: 25 | void slot_RadioButton_checket(int); 26 | private: 27 | void WidgetValInit(); 28 | 29 | private: 30 | Ui::Widget *ui; 31 | Srceen* srceenWidget; 32 | QButtonGroup* radioGroup; 33 | bool isHide; //是否隐藏当前窗口 34 | 35 | QSystemTrayIcon *trayIcon; //系统托盘 36 | QMenu *trayIconMenu; //菜单 37 | QAction *quitAction; //退出 38 | QAction *screenShotAction; //截图 39 | }; 40 | 41 | #endif // WIDGET_H 42 | -------------------------------------------------------------------------------- /SrceenWidget/widget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Widget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 400 10 | 300 11 | 12 | 13 | 14 | Widget 15 | 16 | 17 | 18 | 19 | 100 20 | 120 21 | 75 22 | 23 23 | 24 | 25 | 26 | 截屏 27 | 28 | 29 | 30 | 31 | 32 | 100 33 | 170 34 | 141 35 | 31 36 | 37 | 38 | 39 | 截图时隐藏当前窗口 40 | 41 | 42 | true 43 | 44 | 45 | 46 | 47 | 48 | 100 49 | 220 50 | 89 51 | 16 52 | 53 | 54 | 55 | 其他 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /ThreadDemo/ThreadDemo.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2020-05-13T22:05:58 4 | # 5 | #------------------------------------------------- 6 | 7 | QT += core gui 8 | 9 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 10 | 11 | TARGET = ThreadDemo 12 | TEMPLATE = app 13 | 14 | # The following define makes your compiler emit warnings if you use 15 | # any feature of Qt which has been marked as deprecated (the exact warnings 16 | # depend on your compiler). Please consult the documentation of the 17 | # deprecated API in order to know how to port your code away from it. 18 | DEFINES += QT_DEPRECATED_WARNINGS 19 | 20 | # You can also make your code fail to compile if you use deprecated APIs. 21 | # In order to do so, uncomment the following line. 22 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 23 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 24 | 25 | CONFIG += c++11 26 | 27 | SOURCES += \ 28 | main.cpp \ 29 | mainwindow.cpp \ 30 | mythread.cpp 31 | 32 | HEADERS += \ 33 | mainwindow.h \ 34 | mythread.h 35 | 36 | FORMS += \ 37 | mainwindow.ui 38 | 39 | # Default rules for deployment. 40 | qnx: target.path = /tmp/$${TARGET}/bin 41 | else: unix:!android: target.path = /opt/$${TARGET}/bin 42 | !isEmpty(target.path): INSTALLS += target 43 | -------------------------------------------------------------------------------- /ThreadDemo/main.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | 3 | 版权所有 (C), 2001-2011, DeRoy 4 | 5 | ****************************************************************************** 6 | 文 件 名 : main.cpp 7 | 版 本 号 : 初稿 8 | 作 者 : DeRoy 9 | 生成日期 : 2020年8月28日 10 | 最近修改 : 11 | 功能描述 : Tcp_Client 12 | 函数列表 : 13 | * 14 | * 15 | 16 | 修改历史 : 17 | 1.日 期 : 2020年9月7日 18 | 作 者 : DeRoy 19 | 修改内容 : 创建文件 20 | 21 | ******************************************************************************/ 22 | #include "mainwindow.h" 23 | #include 24 | int main(int argc, char *argv[]) 25 | { 26 | QApplication a(argc, argv); 27 | MainWindow w; 28 | w.show(); 29 | 30 | return a.exec(); 31 | } 32 | -------------------------------------------------------------------------------- /ThreadDemo/mainwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include "ui_mainwindow.h" 3 | 4 | MainWindow::MainWindow(QWidget *parent) : 5 | QMainWindow(parent), 6 | ui(new Ui::MainWindow) 7 | { 8 | ui->setupUi(this); 9 | ui->progressBar->setMaximum(100); //设置进度条最大值 10 | ui->progressBar->setValue(0); //设置进度条当前值为0 11 | ui->statusBar->addWidget(ui->progressBar); //将进度条添加进状态栏MainToolBal 12 | 13 | m_ProgressBarVal.moveToThread(&m_thread); //m_ProgressBarVal移动到线程中去 14 | m_thread.start(); //开启线程 15 | //关联信号,当触发checkMyThread()信号时执行MyThreadWork()函数 16 | connect(this,SIGNAL(checkMyThread()),&m_ProgressBarVal,SLOT(MyThreadWork())); 17 | //关联信号,当触发SendVal()信号时执行RecvVal()函数,并将值传递过去 18 | connect(&m_ProgressBarVal,SIGNAL(SendVal(int)),this,SLOT(RecvVal(int))); 19 | } 20 | 21 | MainWindow::~MainWindow() 22 | { 23 | //线程退出并等待10s 24 | m_thread.exit(); 25 | m_thread.wait(1000*10); 26 | delete ui; 27 | } 28 | void MainWindow::RecvVal(int Val) 29 | { 30 | //设置进度条的值 31 | ui->progressBar->setValue(Val); 32 | } 33 | 34 | void MainWindow::on_pushButton_clicked() 35 | { 36 | //触发checkMyThread()信号,使MyThreadWork()工作 37 | emit checkMyThread(); 38 | } 39 | -------------------------------------------------------------------------------- /ThreadDemo/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | #include 6 | #include "mythread.h" 7 | 8 | namespace Ui { 9 | class MainWindow; 10 | } 11 | 12 | class MainWindow : public QMainWindow 13 | { 14 | Q_OBJECT 15 | 16 | public: 17 | explicit MainWindow(QWidget *parent = nullptr); 18 | ~MainWindow(); 19 | signals: 20 | void checkMyThread(); 21 | private slots: 22 | void RecvVal(int Val); 23 | void on_pushButton_clicked(); 24 | 25 | private: 26 | Ui::MainWindow *ui; 27 | QThread m_thread; 28 | MyThread m_ProgressBarVal; 29 | }; 30 | 31 | #endif // MAINWINDOW_H 32 | -------------------------------------------------------------------------------- /ThreadDemo/mainwindow.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 400 10 | 300 11 | 12 | 13 | 14 | MainWindow 15 | 16 | 17 | 18 | 19 | 20 | 250 21 | 210 22 | 118 23 | 23 24 | 25 | 26 | 27 | 24 28 | 29 | 30 | 31 | 32 | 33 | 130 34 | 80 35 | 131 36 | 41 37 | 38 | 39 | 40 | 开始 41 | 42 | 43 | 44 | 45 | 46 | 47 | 0 48 | 0 49 | 400 50 | 23 51 | 52 | 53 | 54 | 55 | 56 | TopToolBarArea 57 | 58 | 59 | false 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /ThreadDemo/mythread.cpp: -------------------------------------------------------------------------------- 1 | #include "mythread.h" 2 | #include 3 | #include 4 | MyThread::MyThread(QObject *parent) : QObject(parent) 5 | { 6 | 7 | } 8 | 9 | void MyThread::MyThreadWork() 10 | { 11 | qDebug()< 4 | class MyThread : public QObject 5 | { 6 | Q_OBJECT 7 | public: 8 | explicit MyThread(QObject *parent = nullptr); 9 | 10 | signals: 11 | //线程向外部发出带Val值得信号 12 | void SendVal(int); 13 | public slots: 14 | //线程工作函数 15 | void MyThreadWork(); 16 | }; 17 | 18 | #endif // MYTHREAD_H 19 | -------------------------------------------------------------------------------- /ThreadDemo/readme.txt: -------------------------------------------------------------------------------- 1 | 将任务移至指定线程实现多线程 -------------------------------------------------------------------------------- /ThreadDemo/test.cpp: -------------------------------------------------------------------------------- 1 | #include "test.h" 2 | 3 | Test::Test(QObject *parent) : QObject(parent) 4 | { 5 | 6 | } 7 | -------------------------------------------------------------------------------- /ThreadDemo/test.h: -------------------------------------------------------------------------------- 1 | #ifndef TEST_H 2 | #define TEST_H 3 | 4 | #include 5 | 6 | class Test : public QObject 7 | { 8 | Q_OBJECT 9 | public: 10 | explicit Test(QObject *parent = nullptr); 11 | 12 | signals: 13 | 14 | public slots: 15 | }; 16 | 17 | #endif // TEST_H 18 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | ### 2020-6-30:多语言国际化 2 | 3 | `Qt_Linguist _Demo` 4 | 5 | ![](https://mmbiz.qpic.cn/mmbiz_png/rS7zDaAwbAsCibvwMFntBfKOjQbOP9n6pRX7XEfV2EVyoFwBx2miaTYiat7uK6CqvLOhOpkQBL4v1Aiao91ibIylcUg/640?wx_fmt=png&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1) 6 | 7 | ![](https://mmbiz.qpic.cn/mmbiz_png/rS7zDaAwbAsCibvwMFntBfKOjQbOP9n6poEibGBfyTbvyjlBrPiaN19mL0g1ONIdlHNoR3mabc2LlAnWpFIyMy5hQ/640?wx_fmt=png&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1) 8 | 9 | ### 2020-7-4:`NotePad` 10 | 11 | ![](https://mmbiz.qpic.cn/mmbiz_png/rS7zDaAwbAvQu9GqxGcnPT6tPpADWbCK31SWlBzLWObQ4PoQP6ZibDnemaKIx1icZwm8uMsAglgT6Z6W3jN5Kuicw/640?wx_fmt=png&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1) 12 | 13 | 14 | 15 | ### 2020-7-25:`数字时钟` 16 | 17 | **Clock** 18 | 19 | ![]() 20 | 21 | ### 2020-8-28:`线程Demo` 22 | 23 | [QThread_Demo_console](https://github.com/ADeRoy/Qt_Demo/tree/master/QThread_Demo_console): 24 | 25 | ![1](https://mmbiz.qpic.cn/mmbiz_gif/rS7zDaAwbAt6kq0EDMZHB8J16snnuaZZWgccibBkONSOroTWHib68WWRHUhl4bynKGMx50Ia8um8RN2IElJ7Eo3A/0?wx_fmt=gif) 26 | 27 | [ThreadDemo](https://github.com/ADeRoy/Qt_Demo/tree/master/ThreadDemo): 28 | 29 | ![2](https://mmbiz.qpic.cn/mmbiz_gif/rS7zDaAwbAt6kq0EDMZHB8J16snnuaZZcxRxp1jnK8DgKQLLEicxcqXIUS6SSbX03joUulVjPWMAJUZI11PjMvw/0?wx_fmt=gif) 30 | 31 | ### 2020-8-28:`简易聊天室` 32 | 33 | `tcp_Server` `tcp_client` 34 | 35 | ![]() 36 | 37 | ### 2020.8.30:`Md5单向加密` 38 | 39 | ![]() 40 | 41 | ### 2020.9.6:`线程的同步和互斥` 42 | 43 | **QThread_QMutex_Demo** 44 | 45 | **QThread_QWaitCondition_Demo** 46 | 47 | ### 2020.9.7:线程池 48 | 49 | **QThreadPool** 50 | 51 | ### 2021.7.1:仿微信截屏精简版 52 | 53 | **SrceenWidget** 54 | 55 | ![请添加图片描述](https://img-blog.csdnimg.cn/132204d3895f4ea68313c331f80f18d7.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQ0NTE5NDg0,size_16,color_FFFFFF,t_70) 56 | 57 | ### 2021.7.1:系统托盘+开机自启功能 58 | 59 | ![请添加图片描述](https://img-blog.csdnimg.cn/9d56342a00874582a8cd305598bbe2e0.png) 60 | 61 | **AutoRunSelf** 62 | 63 | ### 2021.7.29Qt抽屉效果 64 | 65 | **scrollArea-demo** 66 | 67 | ![请添加图片描述](https://img-blog.csdnimg.cn/eee1c0c411cd4403a51bd9633be8fb01.jpg) 68 | 69 | 自定义控件,可将QWidget提升为ToolBoxPow 70 | 71 | 可自定义添加Widget 72 | 73 | 可添加QQ效果WIdget 74 | -------------------------------------------------------------------------------- /scrollArea-demo/Simpson.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/scrollArea-demo/Simpson.jpg -------------------------------------------------------------------------------- /scrollArea-demo/ToolBoxPow.cpp: -------------------------------------------------------------------------------- 1 | #include "ToolBoxPow.h" 2 | #include "qDebug" 3 | #include 4 | 5 | #include 6 | 7 | #define BUTTON_DOWN "QPushButton{"\ 8 | "background-image: url(:/arrow_down_normal.png);"\ 9 | "background-repeat: repeat-no-repeat;"\ 10 | "background-position: left;"\ 11 | "background-origin:content;"\ 12 | "padding-right: 10px;"\ 13 | "}" 14 | 15 | #define BUTTON_RIGHT "QPushButton{"\ 16 | "background-image: url(:/arrow_right_normal.png);"\ 17 | "background-repeat: repeat-no-repeat;"\ 18 | "background-position: left;"\ 19 | "background-origin:content;"\ 20 | "padding-right: 10px;"\ 21 | "}" 22 | 23 | ToolBoxPow::ToolBoxPow(QWidget *parent) 24 | :QWidget(parent) 25 | { 26 | m_height = 0; 27 | m_fillWidget = new QWidget; 28 | 29 | scrollArea = new QScrollArea(this); 30 | scrollArea->setWidgetResizable(true); //设置滚动 31 | //幕布 32 | scrollAreaWidgetContents = new QWidget; 33 | //格子布局管理器 他的父亲是幕布 34 | gridLayout = new QGridLayout(scrollAreaWidgetContents); 35 | gridLayout->setSpacing(0); 36 | gridLayout->setContentsMargins(0, 0, 0, 0); 37 | //垂直布局管理器 38 | verticalLayout = new QVBoxLayout(); 39 | verticalLayout->setMargin(0); //设置外边距 40 | verticalLayout->setSpacing(0);//设置内边距 41 | verticalLayout->setObjectName(QStringLiteral("verticalLayout")); 42 | 43 | //将垂直布局管理器添加给格子布局管理器 44 | gridLayout->addLayout(verticalLayout, 0, 0, 1, 1); 45 | //给滚动区域添加 widget 46 | scrollArea->setWidget(scrollAreaWidgetContents); //设置幕布 47 | 48 | // //竖滚动条和横滚动条都可以一直显示 49 | // scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); 50 | // scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn); 51 | 52 | //设置滑动条的样式 53 | scrollArea->setStyleSheet("QScrollArea{border:0px solid;" 54 | "border-radius: 2px;}" 55 | "QScrollBar:vertical{width: 4px;border:0px solid;" 56 | "border-radius: 2px;margin: 0px,0px,0px,0px;" 57 | "background-color: transparent;background:#e1f0fa;}" 58 | "QScrollBar:vertical:hover{width: 4px;" 59 | "border:0px solid;margin: 0px,0px,0px,0px;background:#e1f0fa;}" 60 | "QScrollBar::handle:vertical{width:4px;background:#c0ddee;" 61 | "border-radius: 2px;height: 40px;}" 62 | "QScrollBar::handle:vertical:hover{background:#c0ddee;" 63 | "border-radius: 2px;}" 64 | "QScrollBar::add-line:vertical{height:11px;background-color: transparent;" 65 | "subcontrol-position:bottom;border:0px solid;" 66 | "border-radius: 2px;}" 67 | "QScrollBar::sub-line:vertical{height:11px;" 68 | "background-color: transparent;subcontrol-position:top;" 69 | "border:0px solid;border-radius: 2px;}" 70 | "QScrollBar::add-page:vertical{background-color: #e1f0fa;" 71 | "border:0px solid;border-radius: 2px;}" 72 | "QScrollBar::sub-page:vertical{background-color: #e1f0fa;" 73 | "border:0px solid;border-radius: 2px;}" 74 | "QScrollBar::up-arrow:vertical{" 75 | "border:0px solid;border-radius: 3px;}" 76 | "QScrollBar::down-arrow:vertical {" 77 | "border:0px solid;border-radius: 3px;}"); 78 | mainGridLayout = new QGridLayout(this); 79 | mainGridLayout->setMargin(0); //设置外边距 80 | mainGridLayout->setSpacing(0);//设置内边距 81 | mainGridLayout->addWidget(scrollArea); 82 | } 83 | /** 84 | * @brief ToolBoxPow::AddGroup 添加分组 每个分组由一个PushButton和QListWidget组成 85 | * @param groupName 分组名为唯一标识变量 86 | */ 87 | void ToolBoxPow::AddGroup(QString groupName) 88 | { 89 | BoxGroup* newGroup = new BoxGroup(scrollAreaWidgetContents); 90 | newGroup->setGroupName(groupName); 91 | 92 | verticalLayout->addWidget(newGroup->getButton(), buttonMap.count()); 93 | verticalLayout->addWidget(newGroup->getWidget(), buttonMap.count() + 1); 94 | verticalLayout->addWidget(m_fillWidget,buttonMap.count() + 2); 95 | 96 | buttonMap.insert(groupName,newGroup); 97 | } 98 | 99 | /** 100 | * @brief ToolBoxPow::AddWidget 给分组添加成员 101 | * @param groupName 组名 102 | * @param name 成员名 103 | * @param path 头像路径 104 | */ 105 | void ToolBoxPow::AddQQWidget(QString groupName, QString name, QString path) 106 | { 107 | QWidget *widget=new QWidget(scrollAreaWidgetContents); 108 | QLabel *touLabel = new QLabel(widget); 109 | QLabel *namelabel=new QLabel(widget); 110 | 111 | //设置不同控件的样式 112 | widget->setStyleSheet(" background: transparent"); 113 | namelabel->setFixedSize(180,60); 114 | namelabel->move(80,10); 115 | namelabel->setText(name); 116 | namelabel->setAlignment(Qt::AlignLeft); 117 | namelabel->setAlignment(Qt::AlignVCenter); 118 | QFont font("微软雅黑",11,50); 119 | namelabel->setFont(font); 120 | namelabel->setStyleSheet("color: rgb(70,70,70)"); 121 | touLabel->setFixedSize(50,50); 122 | touLabel->move(15,15); 123 | QPixmap pixmap=QPixmap(path); 124 | QPixmap fitpixmap = pixmap.scaled(50, 50, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); 125 | touLabel->setPixmap(fitpixmap); 126 | touLabel->setScaledContents(true); //设置图片缩放 127 | QMap::iterator ite = buttonMap.find(groupName); 128 | if(ite!=buttonMap.end()) 129 | { 130 | BoxGroup* boxGroup = *ite; 131 | boxGroup->addWidget(widget); 132 | } 133 | } 134 | 135 | void ToolBoxPow::AddWidget(QString groupName, QWidget *widget) 136 | { 137 | QMap::iterator ite = buttonMap.find(groupName); 138 | if(ite!=buttonMap.end()) 139 | { 140 | BoxGroup* boxGroup = *ite; 141 | boxGroup->addWidget(widget); 142 | } 143 | } 144 | 145 | BoxGroup::BoxGroup(QWidget *parent) 146 | { 147 | m_button = new QPushButton(parent); 148 | m_listWidget = new QListWidget(parent); 149 | m_widgetHeight = 0; 150 | m_button->setStyleSheet(BUTTON_RIGHT); //设置样式表 151 | m_button->setMinimumHeight(23); 152 | 153 | m_listWidget->setFrameShape(QListWidget::NoFrame); //这个接口可以使滚动条失效 154 | //先影藏Widget,因为没有成员 155 | m_listWidget->hide(); 156 | m_listWidget->setFixedHeight(m_widgetHeight); //设置 Widget 高度 157 | connect(m_button,SIGNAL(clicked()),this,SLOT(on_pushbutton_checked())); 158 | } 159 | 160 | void BoxGroup::on_pushbutton_checked() 161 | { 162 | if(m_listWidget->isVisible()) 163 | { 164 | m_listWidget->setVisible(false); //or hide() 影藏Widget 165 | m_button->setStyleSheet(BUTTON_RIGHT); 166 | } 167 | else 168 | { 169 | m_listWidget->setVisible(true); 170 | m_button->setStyleSheet(BUTTON_DOWN); 171 | } 172 | } 173 | 174 | void BoxGroup::addWidget(QWidget *widget) 175 | { 176 | QListWidgetItem *item=new QListWidgetItem; 177 | QSize size = item->sizeHint(); //获取item大小 178 | item->setSizeHint(QSize(size.width(), 80)); //设置固定高度 179 | m_listWidget->addItem(item); //listWidget添加Item 180 | m_listWidget->setItemWidget(item, widget); //给Item添加Widget 181 | size = item->sizeHint(); //获取item大小 182 | m_widgetHeight += size.height(); 183 | m_listWidget->setFixedHeight(m_widgetHeight); //设置 Widget 高度 184 | } 185 | -------------------------------------------------------------------------------- /scrollArea-demo/ToolBoxPow.h: -------------------------------------------------------------------------------- 1 | #ifndef TOOLBOXPOW_H 2 | #define TOOLBOXPOW_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | class BoxGroup:public QObject 12 | { 13 | Q_OBJECT 14 | public: 15 | BoxGroup(QWidget *parent = nullptr); 16 | private slots: 17 | void on_pushbutton_checked(); 18 | public: 19 | void setGroupName(QString str){ 20 | m_button->setText(str); 21 | } 22 | void addWidget(QWidget* widget); 23 | int getHeight(){ return m_widgetHeight; } 24 | public: 25 | QPushButton* getButton(){return m_button;} 26 | QWidget* getWidget(){return m_listWidget;} 27 | private: 28 | QPushButton* m_button; 29 | QListWidget* m_listWidget; 30 | int m_widgetHeight; 31 | }; 32 | 33 | class ToolBoxPow : public QWidget 34 | { 35 | Q_OBJECT 36 | public: 37 | ToolBoxPow(QWidget *parent = nullptr); 38 | public: 39 | void AddGroup(QString groupName); 40 | void AddQQWidget(QString groupName,QString name,QString path); 41 | void AddWidget(QString groupName,QWidget* widget); 42 | public: 43 | QVBoxLayout* getLayout(){return verticalLayout;} 44 | private: 45 | QGridLayout*mainGridLayout; 46 | QScrollArea* scrollArea; 47 | QVBoxLayout *verticalLayout; 48 | QGridLayout *gridLayout; 49 | QWidget *m_fillWidget; 50 | int m_height; 51 | QWidget* scrollAreaWidgetContents; 52 | QMap buttonMap; 53 | }; 54 | 55 | 56 | #endif // TOOLBOXPOW_H 57 | -------------------------------------------------------------------------------- /scrollArea-demo/arrow_down_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/scrollArea-demo/arrow_down_normal.png -------------------------------------------------------------------------------- /scrollArea-demo/arrow_right_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/scrollArea-demo/arrow_right_normal.png -------------------------------------------------------------------------------- /scrollArea-demo/bianchenxuexijidi.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/scrollArea-demo/bianchenxuexijidi.jpg -------------------------------------------------------------------------------- /scrollArea-demo/blownbear.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/scrollArea-demo/blownbear.jpg -------------------------------------------------------------------------------- /scrollArea-demo/dog.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/scrollArea-demo/dog.jpg -------------------------------------------------------------------------------- /scrollArea-demo/duolaameng.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/scrollArea-demo/duolaameng.jpg -------------------------------------------------------------------------------- /scrollArea-demo/haimianbob.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/scrollArea-demo/haimianbob.jpg -------------------------------------------------------------------------------- /scrollArea-demo/icebear.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/scrollArea-demo/icebear.jpg -------------------------------------------------------------------------------- /scrollArea-demo/main.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | #include "scrollareatest.h" 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | Widget w; 9 | w.show(); 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /scrollArea-demo/panda.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/scrollArea-demo/panda.jpg -------------------------------------------------------------------------------- /scrollArea-demo/scrollArea-demo.pro: -------------------------------------------------------------------------------- 1 | QT += core gui 2 | 3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 4 | 5 | CONFIG += c++11 6 | 7 | # The following define makes your compiler emit warnings if you use 8 | # any Qt feature that has been marked deprecated (the exact warnings 9 | # depend on your compiler). Please consult the documentation of the 10 | # deprecated API in order to know how to port your code away from it. 11 | DEFINES += QT_DEPRECATED_WARNINGS 12 | 13 | # You can also make your code fail to compile if it uses deprecated APIs. 14 | # In order to do so, uncomment the following line. 15 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 16 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 17 | 18 | SOURCES += \ 19 | ToolBoxPow.cpp \ 20 | main.cpp \ 21 | widget.cpp 22 | 23 | HEADERS += \ 24 | ToolBoxPow.h \ 25 | widget.h 26 | 27 | FORMS += \ 28 | widget.ui 29 | 30 | # Default rules for deployment. 31 | qnx: target.path = /tmp/$${TARGET}/bin 32 | else: unix:!android: target.path = /opt/$${TARGET}/bin 33 | !isEmpty(target.path): INSTALLS += target 34 | 35 | RESOURCES += \ 36 | src.qrc 37 | -------------------------------------------------------------------------------- /scrollArea-demo/src.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | dog.jpg 4 | arrow_down_normal.png 5 | arrow_right_normal.png 6 | blownbear.jpg 7 | duolaameng.jpg 8 | haimianbob.jpg 9 | icebear.jpg 10 | tom.jpg 11 | xiaoxin.jpg 12 | bianchenxuexijidi.jpg 13 | 14 | 15 | -------------------------------------------------------------------------------- /scrollArea-demo/tom.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/scrollArea-demo/tom.jpg -------------------------------------------------------------------------------- /scrollArea-demo/widget.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | #include "ui_widget.h" 3 | #include "ToolBoxPow.h" 4 | 5 | Widget::Widget(QWidget *parent) 6 | : QWidget(parent) 7 | , ui(new Ui::Widget) 8 | { 9 | ui->setupUi(this); 10 | 11 | ui->widget->AddGroup("我的好友"); 12 | ui->widget->AddGroup("家人"); 13 | ui->widget->AddGroup("公众号"); 14 | 15 | ui->widget->AddQQWidget("我的好友","徐大鹏",":/blownbear.jpg"); 16 | ui->widget->AddQQWidget("我的好友","梦凡1号",":/dog.jpg"); 17 | ui->widget->AddQQWidget("我的好友","徐大鹏1号",":/duolaameng.jpg"); 18 | ui->widget->AddQQWidget("我的好友","徐大鹏",":/haimianbob.jpg"); 19 | 20 | ui->widget->AddQQWidget("家人","马化腾",":/icebear.jpg"); 21 | ui->widget->AddQQWidget("家人","马云",":/tom.jpg"); 22 | ui->widget->AddQQWidget("家人","任正非",":/xiaoxin.jpg"); 23 | ui->widget->AddQQWidget("家人","雷军",":/haimianbob.jpg"); 24 | 25 | ui->widget->AddQQWidget("公众号","编程学习基地",":/bianchenxuexijidi.jpg"); 26 | ui->widget->AddQQWidget("公众号","果果小师弟",":/duolaameng.jpg"); 27 | ui->widget->AddQQWidget("公众号","码农有道",":/tom.jpg"); 28 | ui->widget->AddQQWidget("公众号","字节流动",":/xiaoxin.jpg"); 29 | 30 | QPushButton* button = new QPushButton; 31 | button->setText("自定义Widget"); 32 | ui->widget->AddWidget("我的好友",button); 33 | } 34 | 35 | Widget::~Widget() 36 | { 37 | delete ui; 38 | } 39 | 40 | -------------------------------------------------------------------------------- /scrollArea-demo/widget.h: -------------------------------------------------------------------------------- 1 | #ifndef WIDGET_H 2 | #define WIDGET_H 3 | 4 | #include 5 | 6 | QT_BEGIN_NAMESPACE 7 | namespace Ui { class Widget; } 8 | QT_END_NAMESPACE 9 | 10 | class Widget : public QWidget 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | Widget(QWidget *parent = nullptr); 16 | ~Widget(); 17 | 18 | private: 19 | Ui::Widget *ui; 20 | }; 21 | #endif // WIDGET_H 22 | -------------------------------------------------------------------------------- /scrollArea-demo/widget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Widget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 265 10 | 529 11 | 12 | 13 | 14 | Widget 15 | 16 | 17 | 18 | 0 19 | 20 | 21 | 0 22 | 23 | 24 | 0 25 | 26 | 27 | 0 28 | 29 | 30 | 0 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | ToolBoxPow 40 | QWidget 41 |
toolboxpow.h
42 | 1 43 |
44 |
45 | 46 | 47 |
48 | -------------------------------------------------------------------------------- /scrollArea-demo/xiaoxin.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ADeRoy/Qt_Demo/b7e1b9b9572464ff9643bc06fbe0356d82fd1757/scrollArea-demo/xiaoxin.jpg -------------------------------------------------------------------------------- /tcp_Server/main.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | 3 | 版权所有 (C), 2001-2011, DeRoy 4 | 5 | ****************************************************************************** 6 | 文 件 名 : main.cpp 7 | 版 本 号 : 初稿 8 | 作 者 : DeRoy 9 | 生成日期 : 2020年8月28日 10 | 最近修改 : 11 | 功能描述 : Tcp_Server 12 | 函数列表 : 13 | * 14 | * 15 | 16 | 修改历史 : 17 | 1.日 期 : 2020年9月7日 18 | 作 者 : DeRoy 19 | 修改内容 : 创建文件 20 | 21 | ******************************************************************************/ 22 | 23 | #include "widget.h" 24 | #include 25 | 26 | int main(int argc, char *argv[]) 27 | { 28 | QApplication a(argc, argv); 29 | Widget w; 30 | w.show(); 31 | 32 | return a.exec(); 33 | } 34 | -------------------------------------------------------------------------------- /tcp_Server/tcp_Server.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2020-05-16T23:56:49 4 | # 5 | #------------------------------------------------- 6 | 7 | QT += core gui network 8 | 9 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 10 | 11 | TARGET = tcpP_Server 12 | TEMPLATE = app 13 | 14 | # The following define makes your compiler emit warnings if you use 15 | # any feature of Qt which has been marked as deprecated (the exact warnings 16 | # depend on your compiler). Please consult the documentation of the 17 | # deprecated API in order to know how to port your code away from it. 18 | DEFINES += QT_DEPRECATED_WARNINGS 19 | 20 | # You can also make your code fail to compile if you use deprecated APIs. 21 | # In order to do so, uncomment the following line. 22 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 23 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 24 | 25 | CONFIG += c++11 26 | 27 | SOURCES += \ 28 | main.cpp \ 29 | widget.cpp 30 | 31 | HEADERS += \ 32 | widget.h 33 | 34 | FORMS += \ 35 | widget.ui 36 | 37 | # Default rules for deployment. 38 | qnx: target.path = /tmp/$${TARGET}/bin 39 | else: unix:!android: target.path = /opt/$${TARGET}/bin 40 | !isEmpty(target.path): INSTALLS += target 41 | -------------------------------------------------------------------------------- /tcp_Server/widget.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | #include "ui_widget.h" 3 | 4 | Widget::Widget(QWidget *parent) : 5 | QWidget(parent), 6 | ui(new Ui::Widget) 7 | { 8 | ui->setupUi(this); 9 | this->setWindowTitle("Server"); 10 | mServer = new QTcpServer; 11 | enumIpAddress(); 12 | 13 | //处理新连接客户端 14 | connect(mServer, SIGNAL(newConnection()),this, SLOT(newConnectionSlot())); 15 | } 16 | 17 | Widget::~Widget() 18 | { 19 | delete ui; 20 | } 21 | void Widget::enumIpAddress() 22 | { 23 | QList ipList = QNetworkInterface::allAddresses(); 24 | QStringList addressStrList; 25 | addressStrList.clear(); 26 | 27 | for(int index = 0;indexcomboBox_Address->addItems(addressStrList); 35 | } 36 | 37 | void Widget::on_pushButton_listen_clicked() 38 | { 39 | QString serverAddressStr = ui->comboBox_Address->currentText(); //获取服务器ip地址 40 | quint16 port = ui->lineEdit_port->text().toInt(); //获取服务器端口 41 | QHostAddress serverAddress = QHostAddress(serverAddressStr); //初始化协议族 42 | 43 | if(mServer->isListening()) 44 | { 45 | //在监听状态 取消监听 46 | mServer->close(); 47 | ui->pushButton_listen->setText("监听"); 48 | } 49 | else 50 | { 51 | //不在监听状态 开始监听 52 | if(mServer->listen(serverAddress, port)) 53 | { 54 | //监听成功 55 | qDebug() << "Listen Ok!!"; 56 | ui->pushButton_listen->setText("停止监听"); 57 | } 58 | else 59 | { 60 | //监听失败 61 | QMessageBox::warning(this, "Tcp Server Listen Error", mServer->errorString()); 62 | } 63 | } 64 | } 65 | 66 | void Widget::newConnectionSlot() 67 | { 68 | qDebug()<<"new connect signal"; 69 | QString clientInfo; 70 | 71 | mClient = mServer->nextPendingConnection(); 72 | mClientList.append(mClient); 73 | //窥视Client 信息 74 | clientInfo = mClient->peerAddress().toString() + ":"+ QString::number(mClient->peerPort()); 75 | ui->listWidget_client->addItem(clientInfo); 76 | 77 | connect(mClient, SIGNAL(readyRead()),this, SLOT(readyReadSlot())); //接收消息 78 | connect(mClient, SIGNAL(disconnected()),this, SLOT(disconnectedSlot())); //断开连接 79 | } 80 | 81 | void Widget::readyReadSlot() 82 | { 83 | QByteArray recvArray; 84 | QTcpSocket* current = nullptr; 85 | if(!mClientList.isEmpty()) 86 | { 87 | //接收客户端数据 88 | for(int index = 0;index < mClientList.count();index ++) 89 | { 90 | current = mClientList.at(index); 91 | 92 | if(current->isReadable()) 93 | { 94 | recvArray = current->readAll(); 95 | if(recvArray.isEmpty()) continue; 96 | QString str = QString(QDateTime::currentDateTime().toString("yyyy.MM.dd hh:mm:ss ddd")) + 97 | ":Recv\n" + str.fromLocal8Bit(recvArray.data()); //本地GBK转Unicode 解决乱码 98 | ui->textBrowser_recv->append(str); 99 | break; 100 | } 101 | } 102 | //转发给其他客户端 103 | for(int index = 0;index < mClientList.count();index ++) 104 | { 105 | QTcpSocket* temp = mClientList.at(index); 106 | if(current == temp) continue; 107 | if(temp->isWritable()) 108 | { 109 | temp->write(recvArray); 110 | } 111 | } 112 | } 113 | 114 | // if(mClient!=nullptr) 115 | // { 116 | // if(mClient->isReadable()) 117 | // { 118 | // QByteArray recvArray = mClient->readAll(); 119 | // QString str = QString(QDateTime::currentDateTime().toString("yyyy.MM.dd hh:mm:ss ddd")) + 120 | // ":Recv\n" + str.fromLocal8Bit(recvArray.data()); //本地GBK转Unicode 解决乱码 121 | // ui->textBrowser_recv->append(str); 122 | // } 123 | // } 124 | } 125 | 126 | void Widget::disconnectedSlot() 127 | { 128 | QString str = QString(QDateTime::currentDateTime().toString("yyyy.MM.dd hh:mm:ss ddd")) 129 | + "client close.."; 130 | ui->textBrowser_recv->append(str); 131 | } 132 | 133 | void Widget::on_pushButton_send_clicked() 134 | { 135 | QString sendString = ui->plainTextEdit_send->toPlainText(); 136 | QByteArray sendArr = sendString.toLocal8Bit(); 137 | 138 | //群发给所有客户端连接 139 | if(!mClientList.isEmpty()) 140 | { 141 | for(int index = 0;index < mClientList.count();index ++) 142 | { 143 | QTcpSocket* temp = mClientList.at(index); 144 | if(temp->isWritable()) 145 | { 146 | temp->write(sendArr); 147 | } 148 | } 149 | } 150 | QString str = QString(QDateTime::currentDateTime().toString("yyyy.MM.dd hh:mm:ss ddd")) 151 | + ":Send\n" + sendString; 152 | ui->textBrowser_recv->append(str); //本地GBK转Unicode 解决乱码 153 | 154 | // //一对一发送,只会发送给最近的一个客户端连接 155 | // if(mClient!=nullptr) 156 | // { 157 | // if(mClient->isWritable()) 158 | // { 159 | // QString sendString = ui->plainTextEdit_send->toPlainText(); 160 | // QByteArray sendArr = sendString.toLocal8Bit(); 161 | // mClient->write(sendArr); 162 | 163 | // QString str = QString(QDateTime::currentDateTime().toString("yyyy.MM.dd hh:mm:ss ddd")) 164 | // + ":Send\n" + sendString; 165 | // ui->textBrowser_recv->append(str); //本地GBK转Unicode 解决乱码 166 | // } 167 | // } 168 | } 169 | 170 | -------------------------------------------------------------------------------- /tcp_Server/widget.h: -------------------------------------------------------------------------------- 1 | #ifndef WIDGET_H 2 | #define WIDGET_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | namespace Ui { 13 | class Widget; 14 | } 15 | 16 | class Widget : public QWidget 17 | { 18 | Q_OBJECT 19 | 20 | public: 21 | explicit Widget(QWidget *parent = nullptr); 22 | ~Widget(); 23 | private slots: 24 | void on_pushButton_listen_clicked();//开始监听 25 | void newConnectionSlot(); //新连接 26 | void disconnectedSlot(); //断开连接 27 | void readyReadSlot(); //接收消息的槽函数 28 | void on_pushButton_send_clicked(); 29 | private: 30 | void enumIpAddress(); 31 | private: 32 | Ui::Widget *ui; 33 | 34 | QTcpServer *mServer; 35 | QTcpSocket *mClient = nullptr; 36 | QListmClientList; 37 | }; 38 | 39 | #endif // WIDGET_H 40 | -------------------------------------------------------------------------------- /tcp_Server/widget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Widget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 509 10 | 383 11 | 12 | 13 | 14 | Widget 15 | 16 | 17 | 18 | 19 | 420 20 | 20 21 | 75 22 | 23 23 | 24 | 25 | 26 | QPushButton{ 27 | 28 | color: rgb(255, 255, 255); 29 | border-style: solid; 30 | border-radius: 5px; 31 | background-color: rgb(6, 163, 220); 32 | } 33 | 34 | QPushButton:hover{ 35 | background-color: rgb(16, 196, 245); 36 | } 37 | 38 | QPushButton:pressed { 39 | background-color: rgb(3, 130, 176); 40 | } 41 | 42 | 43 | 监听 44 | 45 | 46 | 47 | 48 | 49 | 360 50 | 60 51 | 141 52 | 311 53 | 54 | 55 | 56 | QListWidget { 57 | border-style: none; 58 | border-radius: 5px; 59 | padding: 3px; 60 | background: transparent; 61 | border: 2px solid #3498db; 62 | } 63 | QTextEdit:!enabled { 64 | color: #525252; 65 | } 66 | 67 | 68 | 69 | 70 | 71 | 20 72 | 60 73 | 331 74 | 261 75 | 76 | 77 | 78 | QTextEdit { 79 | border-style: none; 80 | border-radius: 5px; 81 | padding: 3px; 82 | background: transparent; 83 | border: 1px solid #3498db; 84 | } 85 | QTextEdit:focus { 86 | border: 2px solid #3498db; 87 | } 88 | QTextEdit:!enabled { 89 | color: #525252; 90 | } 91 | 92 | 93 | 94 | 95 | 96 | 20 97 | 340 98 | 251 99 | 31 100 | 101 | 102 | 103 | QPlainTextEdit { 104 | border-style: none; 105 | border-radius: 5px; 106 | padding: 3px; 107 | background: transparent; 108 | border: 1px solid #3498db; 109 | } 110 | QPlainTextEdit:focus { 111 | border: 2px solid #3498db; 112 | } 113 | QPlainTextEdit:!enabled { 114 | color: #525252; 115 | } 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 280 125 | 342 126 | 75 127 | 31 128 | 129 | 130 | 131 | QPushButton{ 132 | 133 | color: rgb(255, 255, 255); 134 | border-style: solid; 135 | border-radius: 5px; 136 | background-color: rgb(6, 163, 220); 137 | } 138 | 139 | QPushButton:hover{ 140 | background-color: rgb(16, 196, 245); 141 | } 142 | 143 | QPushButton:pressed { 144 | background-color: rgb(3, 130, 176); 145 | } 146 | 147 | 148 | 发送 149 | 150 | 151 | 152 | 153 | 154 | 230 155 | 20 156 | 181 157 | 28 158 | 159 | 160 | 161 | 162 | 163 | 164 | QLabel { 165 | border:none; 166 | color:#3498db; 167 | } 168 | 169 | 170 | 本地端口号: 171 | 172 | 173 | 174 | 175 | 176 | 177 | QLineEdit 178 | { 179 | border-style: none; 180 | border-radius: 5px; 181 | padding: 3px; 182 | background: transparent; 183 | border: 2px solid #3498db; 184 | } 185 | 186 | 187 | 8080 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 20 197 | 20 198 | 72 199 | 16 200 | 201 | 202 | 203 | QLabel { 204 | border:none; 205 | color:#3498db; 206 | } 207 | 208 | 209 | 本地IP地址: 210 | 211 | 212 | 213 | 214 | 215 | 100 216 | 20 217 | 111 218 | 21 219 | 220 | 221 | 222 | QComboBox{ 223 | color: rgb(255, 255, 255); 224 | border-style: solid; 225 | border-radius: 1px; 226 | background-color: rgb(6, 163, 220); 227 | } 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | -------------------------------------------------------------------------------- /tcp_client/main.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | 3 | 版权所有 (C), 2001-2011, DeRoy 4 | 5 | ****************************************************************************** 6 | 文 件 名 : main.cpp 7 | 版 本 号 : 初稿 8 | 作 者 : DeRoy 9 | 生成日期 : 2020年8月28日 10 | 最近修改 : 11 | 功能描述 : Tcp_Client 12 | 函数列表 : 13 | * 14 | * 15 | 16 | 修改历史 : 17 | 1.日 期 : 2020年9月7日 18 | 作 者 : DeRoy 19 | 修改内容 : 创建文件 20 | 21 | ******************************************************************************/ 22 | #include "widget.h" 23 | #include 24 | 25 | int main(int argc, char *argv[]) 26 | { 27 | QApplication a(argc, argv); 28 | Widget w; 29 | w.show(); 30 | 31 | return a.exec(); 32 | } 33 | -------------------------------------------------------------------------------- /tcp_client/tcp_client.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2020-05-18T13:52:48 4 | # 5 | #------------------------------------------------- 6 | 7 | QT += core gui network 8 | 9 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 10 | 11 | TARGET = tcp_client 12 | TEMPLATE = app 13 | 14 | # The following define makes your compiler emit warnings if you use 15 | # any feature of Qt which has been marked as deprecated (the exact warnings 16 | # depend on your compiler). Please consult the documentation of the 17 | # deprecated API in order to know how to port your code away from it. 18 | DEFINES += QT_DEPRECATED_WARNINGS 19 | 20 | # You can also make your code fail to compile if you use deprecated APIs. 21 | # In order to do so, uncomment the following line. 22 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 23 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 24 | 25 | CONFIG += c++11 26 | 27 | SOURCES += \ 28 | main.cpp \ 29 | widget.cpp 30 | 31 | HEADERS += \ 32 | widget.h 33 | 34 | FORMS += \ 35 | widget.ui 36 | 37 | # Default rules for deployment. 38 | qnx: target.path = /tmp/$${TARGET}/bin 39 | else: unix:!android: target.path = /opt/$${TARGET}/bin 40 | !isEmpty(target.path): INSTALLS += target 41 | -------------------------------------------------------------------------------- /tcp_client/widget.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | #include "ui_widget.h" 3 | 4 | Widget::Widget(QWidget *parent) : 5 | QWidget(parent), 6 | ui(new Ui::Widget) 7 | { 8 | ui->setupUi(this); 9 | this->setWindowTitle("Client"); 10 | socket = new QTcpSocket; 11 | socketState = false; 12 | 13 | connect(socket, SIGNAL(disconnected()),this, SLOT(disconnectedSlot())); //客户端断开连接 14 | connect(socket, SIGNAL(readyRead()),this, SLOT(readyReadSlot())); //接收消息 15 | } 16 | 17 | Widget::~Widget() 18 | { 19 | delete ui; 20 | } 21 | 22 | /* 开始连接 */ 23 | void Widget::on_pushButtonConnect_clicked() 24 | { 25 | QString ipAddressStr = ui->lineEditAddress->text(); 26 | quint16 port = ui->lineEditPort->text().toInt(); 27 | 28 | if(!socketState) 29 | { 30 | socket->connectToHost(ipAddressStr, port); 31 | if(socket->waitForConnected(3000)) 32 | { 33 | qDebug() << "Connect2Server OK"; 34 | ui->pushButtonConnect->setText("断开连接"); 35 | socketState = true; 36 | } 37 | else 38 | { 39 | qDebug() << socket->errorString(); 40 | return; 41 | } 42 | } 43 | else 44 | { 45 | socket->close(); //触发disconnected()信号 46 | ui->pushButtonConnect->setText("连接"); 47 | socketState = false; 48 | } 49 | } 50 | 51 | void Widget::disconnectedSlot() 52 | { 53 | qDebug()<<"Socket close"; 54 | } 55 | 56 | void Widget::readyReadSlot() 57 | { 58 | QByteArray dataBa = socket->readAll(); 59 | 60 | QString str = QString(QDateTime::currentDateTime().toString("yyyy.MM.dd hh:mm:ss ddd")) + 61 | ":Recv\n" + str.fromLocal8Bit(dataBa.data()); //本地GBK转Unicode 解决乱码 62 | ui->textBrowserRecv->append(QString(str)); //送显示 63 | } 64 | 65 | void Widget::on_pushButtonSend_clicked() 66 | { 67 | QString dataStr = ui->textEditSend->toPlainText(); 68 | //QByteArray data = dataStr.toUtf8(); //发送UTF编码数据 69 | QByteArray data = dataStr.toLocal8Bit(); //发送本地字符(GBK) 70 | 71 | if(socket->isOpen() && socket->isValid()) 72 | { 73 | socket->write(data); 74 | } 75 | 76 | QString str = QString(QDateTime::currentDateTime().toString("yyyy.MM.dd hh:mm:ss ddd")) + 77 | ":Send\n" + str.fromLocal8Bit(data.data()); //本地GBK转Unicode 解决乱码 78 | ui->textBrowserRecv->append(QString(str)); //送显示 79 | } 80 | -------------------------------------------------------------------------------- /tcp_client/widget.h: -------------------------------------------------------------------------------- 1 | #ifndef WIDGET_H 2 | #define WIDGET_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | namespace Ui { 10 | class Widget; 11 | } 12 | 13 | class Widget : public QWidget 14 | { 15 | Q_OBJECT 16 | 17 | public: 18 | explicit Widget(QWidget *parent = nullptr); 19 | ~Widget(); 20 | 21 | private slots: 22 | void on_pushButtonConnect_clicked(); 23 | void disconnectedSlot(); 24 | void readyReadSlot(); 25 | void on_pushButtonSend_clicked(); 26 | 27 | private: 28 | Ui::Widget *ui; 29 | QTcpSocket *socket; 30 | bool socketState; 31 | }; 32 | 33 | #endif // WIDGET_H 34 | -------------------------------------------------------------------------------- /tcp_client/widget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Widget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 496 10 | 349 11 | 12 | 13 | 14 | Widget 15 | 16 | 17 | 18 | 19 | 0 20 | 30 21 | 491 22 | 241 23 | 24 | 25 | 26 | 数据接收 27 | 28 | 29 | 30 | 31 | 32 | QTextEdit { 33 | border-style: none; 34 | border-radius: 5px; 35 | padding: 3px; 36 | background: transparent; 37 | border: 1px solid #3498db; 38 | } 39 | QTextEdit:focus { 40 | border: 2px solid #3498db; 41 | } 42 | QTextEdit:!enabled { 43 | color: #525252; 44 | } 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 0 54 | 280 55 | 491 56 | 61 57 | 58 | 59 | 60 | 数据发送 61 | 62 | 63 | 64 | 65 | 400 66 | 20 67 | 75 68 | 31 69 | 70 | 71 | 72 | QPushButton{ 73 | 74 | color: rgb(255, 255, 255); 75 | border-style: solid; 76 | border-radius: 5px; 77 | background-color: rgb(6, 163, 220); 78 | } 79 | 80 | QPushButton:hover{ 81 | background-color: rgb(16, 196, 245); 82 | } 83 | 84 | QPushButton:pressed { 85 | background-color: rgb(3, 130, 176); 86 | } 87 | 88 | 89 | 发送 90 | 91 | 92 | 93 | 94 | 95 | 14 96 | 20 97 | 381 98 | 31 99 | 100 | 101 | 102 | QTextEdit { 103 | border-style: none; 104 | border-radius: 5px; 105 | padding: 3px; 106 | background: transparent; 107 | border: 1px solid #3498db; 108 | } 109 | QTextEdit:focus { 110 | border: 2px solid #3498db; 111 | } 112 | QTextEdit:!enabled { 113 | color: #525252; 114 | } 115 | 116 | 117 | 118 | 119 | 120 | 121 | 14 122 | 0 123 | 401 124 | 28 125 | 126 | 127 | 128 | 129 | 130 | 131 | 服务器ip地址: 132 | 133 | 134 | 135 | 136 | 137 | 138 | QLineEdit 139 | { 140 | border-style: none; 141 | border-radius: 5px; 142 | padding: 3px; 143 | background: transparent; 144 | border: 2px solid #3498db; 145 | } 146 | 147 | 148 | 000.000.000.000 149 | 150 | 151 | 169.254.164.127 152 | 153 | 154 | Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter 155 | 156 | 157 | 158 | 159 | 160 | 161 | 服务器端口号: 162 | 163 | 164 | 165 | 166 | 167 | 168 | QLineEdit 169 | { 170 | border-style: none; 171 | border-radius: 5px; 172 | padding: 3px; 173 | background: transparent; 174 | border: 2px solid #3498db; 175 | } 176 | 177 | 178 | 8080 179 | 180 | 181 | Qt::AlignCenter 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 420 191 | 0 192 | 71 193 | 31 194 | 195 | 196 | 197 | QPushButton{ 198 | 199 | color: rgb(255, 255, 255); 200 | border-style: solid; 201 | border-radius: 5px; 202 | background-color: rgb(6, 163, 220); 203 | } 204 | 205 | QPushButton:hover{ 206 | background-color: rgb(16, 196, 245); 207 | } 208 | 209 | QPushButton:pressed { 210 | background-color: rgb(3, 130, 176); 211 | } 212 | 213 | 214 | 连接服务器 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | --------------------------------------------------------------------------------