来自http://blog.csdn.net/qianguozheng/article/details/6849293

最近在做Qt网络编程,主要是项目需要,学习下Qt下网络编程的多线程实现。

1。QTcpSocket 中的connectToHost() 是void类型的,所以调用这个函数后无论是否连上就发送数据的话,在未连接的情况下会出现如下错误

QNativeSocketEngine::write() was not called in QAbstractSocket::ConnectedState

解决方法:通过connected() 信号设置bool变量值,根据bool值判断是否发送数据
 2。

下面的是因为没有指定 connect的链接方向 Qt::DirectConnection

默认会发送给主线程即默认的连接Qt::AutoConnection ,如果是多线程的话就是Qt::QueuedConnection了,所以要明确指定

[cpp] view plaincopyprint?
  1. QObject::connect: Cannot queue arguments of type 'QAbstractSocket::SocketError'
  2. (Make sure 'QAbstractSocket::SocketError' is registered using qRegisterMetaType
  3. ().)
QObject::connect: Cannot queue arguments of type 'QAbstractSocket::SocketError'
(Make sure 'QAbstractSocket::SocketError' is registered using qRegisterMetaType
().)

This enum describes the types of connection that can be used between signals and slots. In particular, it determines whether a particular signal is delivered to a slot immediately or queued for delivery at a later time.

Constant Value Description
Qt::AutoConnection 0 (default) Same as DirectConnection, if the emitter and receiver are in the same thread. Same as QueuedConnection, if the emitter and receiver are in different threads.
Qt::DirectConnection 1 The slot is invoked immediately, when the signal is emitted.
Qt::QueuedConnection 2 The slot is invoked when control returns to the event loop of the receiver's thread. The slot is executed in the receiver's thread.
Qt::BlockingQueuedConnection 4 Same as QueuedConnection, except the current thread blocks until the slot returns. This connection type should only be used where the emitter and receiver are in different threads. Note: Violating this rule can cause your application to deadlock.
Qt::UniqueConnection 0x80 Same as AutoConnection, but the connection is made only if it does not duplicate an existing connection. i.e., if the same signal is already connected to the same slot for the same pair of objects, then the connection will fail. This connection type was introduced in Qt 4.6.
Qt::AutoCompatConnection 3 The default type when Qt 3 support is enabled. Same as AutoConnection but will also cause warnings to be output in certain situations. See Compatibility Signals and Slots for further information.

3。

注册这个宏,我就不是很理解,请各位指教,谢谢,mark下

int type1=qRegisterMetaType<QAbstractSocket::SocketError>("SocketError");

4。

在多线程socket编程中 ,在每个run函数的末尾加上exec();不知道是什么原因,这个消息循环必须添加,不然程序不能正常执行,

我的猜测是让线程一直在这个位置循环吧,具体的我也讲不太清楚。请高手详解,谢谢

http://blog.csdn.net/vah101/article/details/5980070

http://www.qtcentre.org/threads/6168-QSocketNotifier-socket-notifiers-cannot-be-disabled-from-another-thread

Qt之网络编程错误总结相关推荐

  1. Qt扫盲-网络编程概述

    网络编程概述 一.Qt网络编程概述 二.Qt对Http,FTP应用层协议支持 三.TCP通信编程支持 四.UDP通信编程支持 五.主机信息的获取 六.网络代理 七.底层管理的支持 一.Qt网络编程概述 ...

  2. linux网络编程 错误,网络编程的异常及处理

    网络编程不只是编写网络.主机.进程都正常时能良好工作的进程,更重要的是客户主机崩溃.客户进程崩溃网络异常时怎么处理. accept被信号中断 accept以及套接字上的I/O可能被信号打断,并返回EI ...

  3. qt android 网络编程实例,QT网络编程Tcp下C/S架构的即时通信实例

    先写一个客户端,实现简单的,能加入聊天,以及加入服务器的界面. #ifndef TCPCLIENT_H #define TCPCLIENT_H #include #include #include # ...

  4. Qt网络编程错误总结

    1.报错提示 QObject::connect: Cannot queue arguments of type 'QAbstractSocket::SocketError' (Make sure 'Q ...

  5. QT socket网络编程

    全是自我理解,如有错误的地方可留言提示,谢谢! 开发工具:QT Creator 前提: 1.创建两个项目:server client 2.在两个项目的.pro文件中添加network QT += co ...

  6. QT多线程网络编程程序崩溃问题与解决

    环境:Ubuntu14.04,Qt5.5 平台:QtCreator 场景:有以下三个线程:1.gstreamer循环取摄像头视频帧,25fps:2.HTTP循环请求消息并显示在QDoubleSpinB ...

  7. Qt开发——网络编程UDP网络广播软件之服务器端

    今天是除夕夜,祝大家除夕快乐 需要和客户端配合使用:https://blog.csdn.net/qq_41895747/article/details/104080462 目录 效果图 QUdpSoc ...

  8. QT实现网络编程---客户端、服务端

    客户端: Client.h #pragma once #include <QtWidgets/QWidget> #include "ui_Client.h" #incl ...

  9. Qt学习笔记之网络编程

    Qt网络模块提供了允许您编写TCP / IP客户端和服务器的类.它提供了代表低级网络概念的低级类(例如QTcpSocket,QTcpServer和QUdpSocket),以及高级类(例如QNetwor ...

最新文章

  1. scala mysql bit_Scala连接mysql数据库
  2. 英语阅读推荐:使用AJAX+WF+LINQ制作Google IG式首页
  3. Linux 软件安装与卸载之获取程序包的途径
  4. ArcGIS Pro发布三维场景服务
  5. Python字典dict的增删查改及常用操作
  6. mdnsresponder_什么是mDNSResponder.exe / Bonjour,如何卸载或删除它?
  7. 玩转oracle 11g(25):手工删除oracle归档日志后操作步骤 和修改用户默认解锁时间
  8. 【转】微服务架构下分布式事务方案
  9. php导入excel文件 视频,PHP导入Excel文件
  10. [数据结构与算法] (顺序)线性表简单demo程序
  11. ES6入门---变量的解构赋值
  12. python-gui-pyqt5的使用方法-8--实际案例可参考使用
  13. 教你编写高性能的mysql语法
  14. 【PAT】A-1076:Forwards on Weibo(有向图的BFS遍历)
  15. 七、文章管理页面及功能实现《iVX低代码/无代码个人博客制作》
  16. CSS - 选择器优先级介绍
  17. error: Apostrophe not preceded by \ (in XXX.)
  18. 【MAX7800实现KWS20 demo演示】
  19. 《计算机是怎样跑起来的》学习笔记
  20. 麻雀要革命2 第44节:怦然心动的星月童话

热门文章

  1. 统一信用代码n开头_农业银行信用卡审批及拒绝代码汇总!
  2. 英文写作笔记--转自知乎
  3. 8086cpu 可编程接口技术(一)
  4. DSUM和Excel表:具有多个条件的总和
  5. “Torch not compiled with CUDA enabled“
  6. Mybatis源码学习第六课---核心层源码分析--binding模块
  7. 携创教育:自考助学加分怎么申请?自考助学加分的规则?
  8. oracle sql 学习记录
  9. android 打开各种文件的方式
  10. 女性收入最高的20个工作一览