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

golang 做网站锦绣大地seo

golang 做网站,锦绣大地seo,做网站难度,上海对外贸易公司界面: 添加了聊天显示区域(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/460337.html

相关文章:

  • 怎样查看网站点击量南通seo
  • 温州网站优化页面知乎关键词排名优化工具
  • 网站运营与网络推广方案搜索引擎网址
  • 网络营销专业就业公司seo收索引擎优化
  • 做分享衣服网站的初衷是什么意思友链交换网站
  • 烟台建设局网站世界足球排名最新
  • 有没有必要为B2B网站做外链百度竞价推广技巧
  • 专做会议发布的网站专业seo网站
  • 新网站怎么做免费国外ddos网站
  • thinkphp做网站教程长沙建站优化
  • 我做微信淘宝客网站百度客服号码
  • 南阳做网站seo的竞价推广托管服务
  • 子网站建设的好处seo与sem的区别和联系
  • 仿政府网站开鲁网站seo不用下载
  • 网站文章页图片不显示北京十大教育培训机构排名
  • 七彩建设发展有限公司官方网站站长统计免费下载
  • html5电影网站如何做苏州seo报价
  • 哪些网站是可以做网络推广的seo算法优化
  • 郑州网站建设培训学校磁力引擎
  • 全国货到付款网站seo推广学院
  • 网站建设培训教程投广告的平台有哪些
  • 快站app官网下载英文seo是什么
  • 武汉企业苏州搜索引擎优化
  • 完全的图片宣传网站怎么做搜索引擎优化包括哪些方面
  • 平面设计十大风格山西seo优化
  • 中山网站建设方案微信引流推广怎么做
  • 荆州网站推广怎么做网站推广的方法有哪些?
  • 大浪网站建设宁波网站推广方案
  • 网站建设网络营销平台 云搜系统互联网推广的好处
  • 用java做的网上购物网站免费的seo