当前位置: 首页 > wzjs >正文

golang 做网站全球疫情最新数据统计

golang 做网站,全球疫情最新数据统计,平面素材网站哪个最好,研发了一个app以后怎么盈利界面: 添加了聊天显示区域(QTextEdit) 添加了发送按钮和清空对话按钮 优化了布局和窗口大小添加了时间戳显示 2、功能: 支持实时对话可以清空对话历史 支持按回车发送消息 添加了简单的关键词匹配响应系统 交互体验&#x…

 

  1. 界面:
  • 添加了聊天显示区域(QTextEdit)
  • 添加了发送按钮和清空对话按钮
  • 优化了布局和窗口大小
  • 添加了时间戳显示

 2、功能:

  • 支持实时对话
  • 可以清空对话历史
  • 支持按回车发送消息
  • 添加了简单的关键词匹配响应系统
  1. 交互体验:
  • 消息自动滚动到底部
  • 清晰的用户/AI消息区分
  • 时间戳显示
  • 更友好的界面提示

目前的 getAIResponse 函数使用了一个简单的关键词匹配系统来模拟AI响应

具体代码:

mainwindow.h

#ifndef MAINWINDOW_H
#define MAINWINDOW_H#include <QMainWindow>
#include <QPushButton>
#include <QLabel>
#include <QLineEdit>
#include <QTextEdit>
#include <QVBoxLayout>
#include <QScrollArea>class MainWindow : public QMainWindow
{Q_OBJECTpublic:MainWindow(QWidget *parent = nullptr);~MainWindow();private slots:void handleSendMessage();void handleClearChat();private:void appendMessage(const QString &message, bool isUser);QString getAIResponse(const QString &userInput);QWidget *centralWidget;QVBoxLayout *mainLayout;QTextEdit *chatDisplay;QLineEdit *inputField;QPushButton *sendButton;QPushButton *clearButton;QScrollArea *scrollArea;
};#endif // MAINWINDOW_H

mainwindow.cpp

#include "mainwindow.h"
#include <QDateTime>
#include <QScrollBar>MainWindow::MainWindow(QWidget *parent): QMainWindow(parent)
{// 创建中心部件centralWidget = new QWidget(this);setCentralWidget(centralWidget);// 创建主布局mainLayout = new QVBoxLayout(centralWidget);// 创建聊天显示区域chatDisplay = new QTextEdit(this);chatDisplay->setReadOnly(true);chatDisplay->setStyleSheet("QTextEdit { background-color: #f5f5f5; }");mainLayout->addWidget(chatDisplay);// 创建输入区域QHBoxLayout *inputLayout = new QHBoxLayout();inputField = new QLineEdit(this);inputField->setPlaceholderText("输入你的问题...");inputLayout->addWidget(inputField);sendButton = new QPushButton("发送", this);inputLayout->addWidget(sendButton);clearButton = new QPushButton("清空对话", this);inputLayout->addWidget(clearButton);mainLayout->addLayout(inputLayout);// 连接信号和槽connect(sendButton, &QPushButton::clicked, this, &MainWindow::handleSendMessage);connect(clearButton, &QPushButton::clicked, this, &MainWindow::handleClearChat);connect(inputField, &QLineEdit::returnPressed, this, &MainWindow::handleSendMessage);// 设置窗口标题和大小setWindowTitle("AI 问答系统");resize(600, 400);// 添加欢迎消息appendMessage("你好!我是AI助手,有什么我可以帮你的吗?", false);
}MainWindow::~MainWindow()
{
}void MainWindow::handleSendMessage()
{QString userInput = inputField->text().trimmed();if (userInput.isEmpty()) {return;}// 显示用户消息appendMessage(userInput, true);inputField->clear();// 获取并显示AI响应QString aiResponse = getAIResponse(userInput);appendMessage(aiResponse, false);
}void MainWindow::handleClearChat()
{chatDisplay->clear();appendMessage("你好!我是AI助手,有什么我可以帮你的吗?", false);
}void MainWindow::appendMessage(const QString &message, bool isUser)
{QString timestamp = QDateTime::currentDateTime().toString("hh:mm:ss");QString formattedMessage = QString("[%1] %2: %3\n").arg(timestamp).arg(isUser ? "你" : "AI").arg(message);chatDisplay->append(formattedMessage);// 滚动到底部QScrollBar *scrollbar = chatDisplay->verticalScrollBar();scrollbar->setValue(scrollbar->maximum());
}QString MainWindow::getAIResponse(const QString &userInput)
{// 这里是一个简单的模拟响应QString response;if (userInput.contains("你好") || userInput.contains("hi") || userInput.contains("hello")) {response = "你好!很高兴见到你。";}else if (userInput.contains("名字")) {response = "我是AI助手,你可以叫我小智。";}else if (userInput.contains("天气")) {response = "抱歉,我目前无法获取实时天气信息。";}else if (userInput.contains("谢谢") || userInput.contains("感谢")) {response = "不客气!如果还有其他问题,随时问我。";}else if (userInput.contains("再见") || userInput.contains("拜拜")) {response = "再见!祝你有愉快的一天!";}else {response = "我理解你的问题,但可能需要更具体的描述。你能详细说明一下吗?";}return response;
}

 main.cpp

#include "mainwindow.h"#include <QApplication>
#include <QLocale>
#include <QTranslator>int main(int argc, char *argv[])
{QApplication a(argc, argv);// QTranslator translator;// const QStringList uiLanguages = QLocale::system().uiLanguages();// for (const QString &locale : uiLanguages) {//     const QString baseName = "QtDemo_" + QLocale(locale).name();//     if (translator.load(":/i18n/" + baseName)) {//         a.installTranslator(&translator);//         break;//     }// }MainWindow w;w.show();return a.exec();
}

 QtDemo.pro

QT       += core guigreaterThan(QT_MAJOR_VERSION, 4): QT += widgetsCONFIG += c++17# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0SOURCES += \main.cpp \mainwindow.cppHEADERS += \mainwindow.hFORMS += \mainwindow.uiTRANSLATIONS += \QtDemo_zh_CN.ts
CONFIG += lrelease
CONFIG += embed_translations# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

 运行

 看不懂你的话可以先看第一个Qt项目

http://www.dtcms.com/wzjs/144408.html

相关文章:

  • 网站开发就业方向百度浏览器网页版入口
  • 徐州建设网站公司如何创建一个属于自己的网站
  • 网站改版意见方案南宁seo排名优化
  • 传奇网站制作网国家免费职业培训平台
  • 最专业的网站建设江苏网站开发
  • 网页设计茶叶网站建设搜索优化网络推广
  • 石家庄外贸网站建设卡一卡二卡三入口2021
  • 武汉门户网关键字排名优化公司
  • wordpress 建站服务肇庆网络推广
  • 重庆网站建设入门培训seo专业优化方法
  • 徐州做网站的公司哪些好地域名网址查询
  • 网站登录模板营销培训总结
  • 宝安小学网站建设建网站seo
  • 供应链管理平台官网seo标题优化关键词怎么选
  • 网站备案流程公安百度推广后台登陆首页
  • 投诉举报网站建设方案中国十大新闻网站排名
  • 网站开发是否属于无形资产成都高薪seo
  • 高端网站建设css3动画响应式模板优化20条措施
  • wordpress apache广州seo公司官网
  • 沈阳网站制作定制策划网络推广策划方案模板
  • 青岛seo网站排名杭州推广平台有哪些
  • 做淘宝店头的网站学seo需要多久
  • 网站开发心路历程在线分析网站
  • 网红网站建设官网关键词挖掘排名
  • 网站备案流程公安合肥seo排名扣费
  • 资阳网站建设 xiuweb西安市seo排名按天优化
  • 安卓是哪个公司开发的网站排名软件优化
  • 网站建设培训课程百度站长平台账号购买
  • 做网站开发前景如何semiconductor是什么意思
  • 网站建设自我总结中国域名注册局官网