客户端:
代码:
#include "MainWindow.h"
#include "ui_MainWindow.h"
#include "ui\MainWindow.h"
#include <QTcpServer>
#include <QBuffer>
#include <QTcpSocket>
#include <opencv2/opencv.hpp>
#include <iostream>
#include <QThread>
using namespace std;
using namespace cv;
//客户端
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect(ui->btnPhto, SIGNAL(clicked()), this, SLOT(BtnPhtoSlot())); //拍照
connect(ui->btnPhto_2, SIGNAL(clicked()), this, SLOT(BtnPhto2Slot())); //拍照
connect(ui->btnConnect, SIGNAL(clicked()), this, SLOT(BtnConnectSlot())); //连接服务端
connect(ui->btnOff, SIGNAL(clicked()), this, SLOT(BtnOffSlot())); //断开服务端
//初始化套接字对象
mSocketM = new QTcpSocket();
}
MainWindow::~MainWindow()
{
delete ui;
delete mSocketM;
//t->closeThread();
//t->wait();
}
void MainWindow::BtnPhto2Slot() //发送数据
{
//QString s = ui->textEdit->toPlainText();
//QByteArray qByteArray = s.toUtf8();
//char* cStr = qByteArray.data();
//int sendRe = mSocketM->write(dataArray);
qDebug() << "sendPicture clicked" << endl;
QBuffer buffer;
buffer.open(QIODevice::ReadWrite);
tempPixmapM.save(&buffer, "bmp");
quint32 pix_len = (quint32)buff