Qt TCP聊天室demo

  • E1_165875
    了解作者
  • 2.2MB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-04-09 22:23
    上传日期
Qt 通过QTcpSocket类和QTcpServer类实现TCP协议的编程。代码介绍如何实现一个如何基于TCP的网络聊天室,他同样也从客户端和服务器两部分组成。
TCP.zip
  • TCP
  • TcpServer
  • TcpServer.pro
    458B
  • tcpclientsocket.cpp
    747B
  • tcpclientsocket.h
    467B
  • tcpserver.h
    662B
  • main.cpp
    181B
  • server.cpp
    1.8KB
  • tcpserver.cpp
    1.2KB
  • server.h
    636B
  • TcpServer.pro.user
    23.4KB
  • build-TcpServer-Desktop_Qt_5_6_3_MinGW_32bit-Debug
  • release
  • debug
  • moc_server.cpp
    4.7KB
  • main.o
    460.1KB
  • moc_tcpclientsocket.cpp
    5.4KB
  • tcpclientsocket.o
    257.3KB
  • moc_server.o
    292.3KB
  • TcpServer.exe
    2.2MB
  • moc_tcpserver.o
    419.7KB
  • server.o
    293.4KB
  • moc_tcpclientsocket.o
    283KB
  • moc_tcpserver.cpp
    3.7KB
  • tcpserver.o
    411.5KB
  • Makefile
    19KB
  • Makefile.Debug
    53.4KB
  • Makefile.Release
    53.6KB
  • TcpClient
  • TcpClient.pro
    372B
  • TcpClient.pro.user
    23.4KB
  • tcpclient.cpp
    4.2KB
  • main.cpp
    181B
  • tcpclient.h
    995B
  • build-TcpClient-Desktop_Qt_5_6_3_MinGW_32bit-Debug
  • release
  • debug
  • main.o
    460.1KB
  • TcpClient.exe
    1.3MB
  • moc_tcpclient.o
    414.7KB
  • moc_tcpclient.cpp
    4KB
  • tcpclient.o
    448.3KB
  • Makefile
    19KB
  • Makefile.Debug
    34.9KB
  • Makefile.Release
    35KB
内容介绍
/**************************************************************************** ** Meta object code from reading C++ file 'tcpclientsocket.h' ** ** Created by: The Qt Meta Object Compiler version 67 (Qt 5.6.3) ** ** WARNING! All changes made in this file will be lost! *****************************************************************************/ #include "../../TcpServer/tcpclientsocket.h" #include <QtCore/qbytearray.h> #include <QtCore/qmetatype.h> #if !defined(Q_MOC_OUTPUT_REVISION) #error "The header file 'tcpclientsocket.h' doesn't include <QObject>." #elif Q_MOC_OUTPUT_REVISION != 67 #error "This file was generated using the moc from 5.6.3. It" #error "cannot be used with the include files from this version of Qt." #error "(The moc has changed too much.)" #endif QT_BEGIN_MOC_NAMESPACE struct qt_meta_stringdata_TcpClientSocket_t { QByteArrayData data[6]; char stringdata0[72]; }; #define QT_MOC_LITERAL(idx, ofs, len) \ Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(len, \ qptrdiff(offsetof(qt_meta_stringdata_TcpClientSocket_t, stringdata0) + ofs \ - idx * sizeof(QByteArrayData)) \ ) static const qt_meta_stringdata_TcpClientSocket_t qt_meta_stringdata_TcpClientSocket = { { QT_MOC_LITERAL(0, 0, 15), // "TcpClientSocket" QT_MOC_LITERAL(1, 16, 13), // "updateClients" QT_MOC_LITERAL(2, 30, 0), // "" QT_MOC_LITERAL(3, 31, 10), // "disconnect" QT_MOC_LITERAL(4, 42, 12), // "dataReceived" QT_MOC_LITERAL(5, 55, 16) // "slotDisconnected" }, "TcpClientSocket\0updateClients\0\0" "disconnect\0dataReceived\0slotDisconnected" }; #undef QT_MOC_LITERAL static const uint qt_meta_data_TcpClientSocket[] = { // content: 7, // revision 0, // classname 0, 0, // classinfo 4, 14, // methods 0, 0, // properties 0, 0, // enums/sets 0, 0, // constructors 0, // flags 2, // signalCount // signals: name, argc, parameters, tag, flags 1, 2, 34, 2, 0x06 /* Public */, 3, 1, 39, 2, 0x06 /* Public */, // slots: name, argc, parameters, tag, flags 4, 0, 42, 2, 0x09 /* Protected */, 5, 0, 43, 2, 0x09 /* Protected */, // signals: parameters QMetaType::Void, QMetaType::QString, QMetaType::Int, 2, 2, QMetaType::Void, QMetaType::Int, 2, // slots: parameters QMetaType::Void, QMetaType::Void, 0 // eod }; void TcpClientSocket::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a) { if (_c == QMetaObject::InvokeMetaMethod) { TcpClientSocket *_t = static_cast<TcpClientSocket *>(_o); Q_UNUSED(_t) switch (_id) { case 0: _t->updateClients((*reinterpret_cast< QString(*)>(_a[1])),(*reinterpret_cast< int(*)>(_a[2]))); break; case 1: _t->disconnect((*reinterpret_cast< int(*)>(_a[1]))); break; case 2: _t->dataReceived(); break; case 3: _t->slotDisconnected(); break; default: ; } } else if (_c == QMetaObject::IndexOfMethod) { int *result = reinterpret_cast<int *>(_a[0]); void **func = reinterpret_cast<void **>(_a[1]); { typedef void (TcpClientSocket::*_t)(QString , int ); if (*reinterpret_cast<_t *>(func) == static_cast<_t>(&TcpClientSocket::updateClients)) { *result = 0; return; } } { typedef void (TcpClientSocket::*_t)(int ); if (*reinterpret_cast<_t *>(func) == static_cast<_t>(&TcpClientSocket::disconnect)) { *result = 1; return; } } } } const QMetaObject TcpClientSocket::staticMetaObject = { { &QTcpSocket::staticMetaObject, qt_meta_stringdata_TcpClientSocket.data, qt_meta_data_TcpClientSocket, qt_static_metacall, Q_NULLPTR, Q_NULLPTR} }; const QMetaObject *TcpClientSocket::metaObject() const { return QObject::d_ptr->metaObject ? QObject::d_ptr->dynamicMetaObject() : &staticMetaObject; } void *TcpClientSocket::qt_metacast(const char *_clname) { if (!_clname) return Q_NULLPTR; if (!strcmp(_clname, qt_meta_stringdata_TcpClientSocket.stringdata0)) return static_cast<void*>(const_cast< TcpClientSocket*>(this)); return QTcpSocket::qt_metacast(_clname); } int TcpClientSocket::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QTcpSocket::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { if (_id < 4) qt_static_metacall(this, _c, _id, _a); _id -= 4; } else if (_c == QMetaObject::RegisterMethodArgumentMetaType) { if (_id < 4) *reinterpret_cast<int*>(_a[0]) = -1; _id -= 4; } return _id; } // SIGNAL 0 void TcpClientSocket::updateClients(QString _t1, int _t2) { void *_a[] = { Q_NULLPTR, const_cast<void*>(reinterpret_cast<const void*>(&_t1)), const_cast<void*>(reinterpret_cast<const void*>(&_t2)) }; QMetaObject::activate(this, &staticMetaObject, 0, _a); } // SIGNAL 1 void TcpClientSocket::disconnect(int _t1) { void *_a[] = { Q_NULLPTR, const_cast<void*>(reinterpret_cast<const void*>(&_t1)) }; QMetaObject::activate(this, &staticMetaObject, 1, _a); } QT_END_MOC_NAMESPACE
评论