-
大小: 2.74MB文件类型: .rar金币: 1下载: 0 次发布日期: 2023-08-16
- 语言: 其他
- 标签: Qt QImage QImageReader QImageWriter
资源简介
Qt用Tcp 和Udp 传图片的例子,对于没做过这方面编程的朋友肯定很有帮助
代码片段和文件信息
/*
* Copyright (c) 2006-2007 Johan Thelin
*
* All rights reserved.
*
* Redistribution and use in source and binary forms with or without modification
* are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* * Neither the name of APress nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* “AS IS“ AND ANY EXPRESS OR IMPLIED WARRANTIES INCLUDING BUT NOT
* LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT INDIRECT INCIDENTAL SPECIAL
* EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING BUT NOT LIMITED TO
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE DATA OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY WHETHER IN CONTRACT STRICT LIABILITY OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include
#include
#include
#include “clientdialog.h“
ClientDialog::ClientDialog() : QDialog()
{
ui.setupUi( this );
connect( ui.getButton SIGNAL(clicked()) this SLOT(getClicked()) );
connect( &socket SIGNAL(error(QAbstractSocket::SocketError)) this SLOT(tcpError(QAbstractSocket::SocketError)) );
connect( &socket SIGNAL(readyRead()) this SLOT(tcpReady()) );
}
void ClientDialog::getClicked()
{
ui.getButton->setEnabled( false );
ui.imageLabel->setPixmap( QPixmap() );
ui.imageLabel->setText( tr(“Getting image...“) );
dataSize = 0;
socket.abort();
socket.connectToHost( ui.serverEdit->text() 9876 );
}
void ClientDialog::tcpReady()
{
if( dataSize == 0 )
{
QDataStream stream( &socket );
stream.setVersion( QDataStream::Qt_4_0 );
if( socket.bytesAvailable() < sizeof(quint32) )
return;
stream >> dataSize;
}
if( dataSize > socket.bytesAvailable() )
return;
QByteArray array = socket.read( dataSize );
QBuffer buffer(&array);
buffer.open( QIODevice::ReadOnly );
QImageReader reader(&buffer “PNG“);
QImage image = reader.read();
if( !image.isNull() )
{
ui.imageLabel->setPixmap( QPixmap::fromImage( image ) );
ui.imageLabel->setText( tr
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 1898 2007-08-04 17:35 udpserver\main.cpp
文件 2682 2007-08-04 17:35 udpserver\sender.cpp
文件 1933 2007-08-04 17:35 udpserver\sender.h
文件 384731 2007-03-16 21:14 udpserver\test.png
文件 377 2007-03-16 21:00 udpserver\udpserver.pro
文件 3479 2007-08-04 17:35 tcpclient\clientdialog.cpp
文件 2089 2007-08-04 17:35 tcpclient\clientdialog.h
文件 4283 2007-08-04 17:33 tcpclient\clientdialog.ui
文件 762136 2010-04-13 16:37 tcpclient\debug\clientdialog.o
文件 723045 2010-04-13 16:37 tcpclient\debug\main.o
文件 2433 2010-04-13 16:37 tcpclient\debug\moc_clientdialog.cpp
文件 734581 2010-04-13 16:37 tcpclient\debug\moc_clientdialog.o
文件 1413139 2010-04-13 16:37 tcpclient\debug\tcpclient.exe
文件 1837 2007-08-04 17:34 tcpclient\main.cpp
文件 6259 2010-04-13 16:37 tcpclient\Makefile
文件 6063 2010-04-13 16:37 tcpclient\Makefile.Debug
文件 6137 2010-04-13 16:37 tcpclient\Makefile.Release
文件 414 2007-02-01 16:14 tcpclient\tcpclient.pro
文件 10346 2010-04-13 16:47 tcpclient\tcpclient.pro.user
文件 6451 2010-04-13 16:37 tcpclient\ui_clientdialog.h
文件 298820 2007-02-01 17:46 tcpserver\debug\images\test-green.png
文件 327442 2007-01-17 17:31 tcpserver\debug\images\test.png
..A.SH. 9216 2010-04-13 16:37 tcpserver\debug\images\Thumbs.db
文件 339868 2010-04-13 16:37 tcpserver\debug\main.o
文件 424824 2010-04-13 16:37 tcpserver\debug\server.o
文件 498358 2010-04-13 16:37 tcpserver\debug\serverthread.o
文件 693560 2010-04-13 16:37 tcpserver\debug\tcpserver.exe
文件 298820 2007-02-01 17:46 tcpserver\images\test-green.png
文件 327442 2007-01-17 17:31 tcpserver\images\test.png
..A.SH. 310272 2010-04-13 16:50 tcpserver\images\Thumbs.db
............此处省略27个文件信息
相关资源
- 高仿360安全卫士9.2界面使用Qt中的qm
- 重新上传esp8266创建mqtt任务,连接mq
- 玩转STM32F103+W5500 MQTT
- QT版学生成绩管理系统源码,未使用数
- mqtt发包工具-压力测试工具
- Qt中将QTableView中的数据导出为Excel文件
- QT学习之TCP聊天
- qt5音乐播放器自定义解码
- qt5音乐播放器,实现歌词同步,本地
- Qt5类继承关系图(增加了书签放大效
- QT影音播放器源码
- 程序打包软件
-
QML的MediaPla
yer支持XP播放视频的dse - 模仿QQ登录窗口Qt
- Qt打砖块游戏
- Qt 串口助手增强版带示波器曲线源代
- QT5获取USB设备信息+PID+VID+序列号+热插
- Qt QML高仿微信
-
Qt以tableWidget/tableView读取xm
l文件,并 - QT状态栏修改
- 使用QT官方库的mqtt客户端
- QT5.12所需ssleay32.dll,libeay32.dll 1.0.2q
-
QT st
yleSheet - 传智播客2016版QT教程
- linux+QT下基于RTP协议的实时视频传输客
- QT 智能家居
- qt写的绘制串口接收到数据的实时曲线
- QT5编译QFtp的具体方法和所用到的资源
- Enigma Virtual Box V7.30官方中文版
- Qt天气助手绘图、获取城市列表
评论
共有 条评论