使用qt编写软件,A软件点击选择图片后,发送给B,B软件接收后,存在三个按钮,分别是对图片进行灰度图处理,翻转处理,OTSU二值化,点击处理后,图片再发送给A(两个软件用TCP通信)
2条回答 默认 最新
关注 引用 皆我百晓生 小程序回复内容作答:
下面是一个使用Qt编写的A软件的示例:#include <QApplication> #include <QWidget> #include <QPushButton> #include <QFileDialog> #include <QTcpSocket> class ASoftware : public QWidget { Q_OBJECT public: ASoftware(QWidget *parent = nullptr) : QWidget(parent) { QPushButton *selectBtn = new QPushButton("选择图片", this); connect(selectBtn, &QPushButton::clicked, this, &ASoftware::selectImage); QPushButton *sendBtn = new QPushButton("发送", this); connect(sendBtn, &QPushButton::clicked, this, &ASoftware::sendImage); tcpSocket = new QTcpSocket(this); connect(tcpSocket, &QTcpSocket::connected, this, &ASoftware::onConnected); } private slots: void selectImage() { QString imageFilePath = QFileDialog::getOpenFileName(this, "选择图片"); // 将图片发送给B软件 // ... } void sendImage() { // 发送图片给B软件 // ... } void onConnected() { // TCP连接建立成功后执行的操作 // ... } private: QTcpSocket *tcpSocket; }; int main(int argc, char *argv[]) { QApplication app(argc, argv); ASoftware aSoftware; aSoftware.show(); return app.exec(); }
以下是使用Qt编写的B软件的示例:
#include <QApplication> #include <QWidget> #include <QPushButton> #include <QTcpServer> #include <QTcpSocket> class BSoftware : public QWidget { Q_OBJECT public: BSoftware(QWidget *parent = nullptr) : QWidget(parent) { QPushButton *grayBtn = new QPushButton("灰度图处理", this); connect(grayBtn, &QPushButton::clicked, this, &BSoftware::processImageToGray); QPushButton *flipBtn = new QPushButton("翻转处理", this); connect(flipBtn, &QPushButton::clicked, this, &BSoftware::processImageToFlip); QPushButton *otsuBtn = new QPushButton("OTSU二值化", this); connect(otsuBtn, &QPushButton::clicked, this, &BSoftware::processImageToOTSU); tcpServer = new QTcpServer(this); connect(tcpServer, &QTcpServer::newConnection, this, &BSoftware::onNewConnection); tcpServer->listen(QHostAddress::Any, 8888); } private slots: void processImageToGray() { // 对接收到的图片进行灰度图处理 // ... } void processImageToFlip() { // 对接收到的图片进行翻转处理 // ... } void processImageToOTSU() { // 对接收到的图片进行OTSU二值化处理 // ... } void onNewConnection() { QTcpSocket *clientConnection = tcpServer->nextPendingConnection(); connect(clientConnection, &QTcpSocket::readyRead, this, &BSoftware::receiveImage); } void receiveImage() { // 接收A软件发送的图片 // ... } private: QTcpServer *tcpServer; }; int main(int argc, char *argv[]) { QApplication app(argc, argv); BSoftware bSoftware; bSoftware.show(); return app.exec(); }
以上是一个使用Qt和C++编写的A软件和B软件的简化示例。在实际应用中,您需要根据具体需求对图像处理部分进行编写,并根据TCP通信协议实现图像的发送和接收。
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 Python 如何安装 distutils模块
- ¥15 关于#网络#的问题:网络是从楼上引一根网线下来,接了2台傻瓜交换机,也更换了ip还是不行
- ¥15 资源泄露软件闪退怎么解决?
- ¥15 CCF-CSP 2023 第三题 解压缩(50%)
- ¥30 comfyui openpose报错
- ¥20 Wpf Datarid单元格闪烁效果的实现
- ¥15 图像分割、图像边缘提取
- ¥15 sqlserver执行存储过程报错
- ¥100 nuxt、uniapp、ruoyi-vue 相关发布问题
- ¥15 浮窗和全屏应用同时存在,全屏应用输入法无法弹出