错误:无法将(null)::readyRead()连接到mythread::readyRead()
Error: Cannot connect (null)::readyRead() to mythread::readyRead()
我正在编写一个多线程服务器,但在"mythrad"类中编译时,我遇到了以下错误:1) 无法将(null)::readyRead()连接到mythread::readyRead()2) 无法将(null)::disconnected()连接到mythread::disconneged()我该怎么修?这是我的代码:
void mythread::run()
{
qDebug() << " Thread started";
connect(m_client, SIGNAL(readyRead()), this, SLOT(readyRead()), Qt::DirectConnection);
connect(m_client, SIGNAL(disconnected()), this, SLOT(disconnected()));
qDebug() << " Client connected";
exec();
}
void mythread::readyRead()
{
QByteArray Data = m_client->readAll();
qDebug()<< " Data in: " << Data;
m_client->write(Data);
}
void mythread::disconnected()
{
qDebug() << " Disconnected";
m_client->deleteLater();
exit(0);
}
myclient:
myclient::myclient(QObject* parent): QObject(parent)
{
QObject::connect(&m_client, SIGNAL(connected()),this, SLOT(startTransfer()));
}
void myclient::start(QString address, quint16 port)
{
QHostAddress LocalHost;
m_client.connectToHost(LocalHost, 6666);
}
void myclient::startTransfer()
{
m_client.write("Hello", 5);
}
m_client
就是nullptr
。
if (m_client) {
connect(m_client, SIGNAL(readyRead()), this, SLOT(readyRead()), Qt::DirectConnection);
}
此外,您不需要从文档中明确断开连接:
所有来往对象的信号都会自动断开连接,并且该对象的任何挂起的已发布事件都会从事件队列中删除。但是,使用deleteLater()通常比直接删除QObject子类更安全。
相关文章:
- 当套接字连接断开时检测C/C++Unix
- 无法在windows上使用mingw将sqlite3与c连接
- 到连接组件算法的问题(递归)
- QTcpSocket在不阻塞GUI的情况下重新连接到服务器
- 无法在C++中建立与MySQL数据库的连接
- PC中的程序和PHONE中的本机描述应用程序之间的数据连接
- 在Qt Creator中,如何在连接到正在运行的进程后查看控制台输出
- 连接 dockerized 模型和 dockerized 数据库时出现"无法 SQLConnect"错误
- 使用 bfs 解决连接组件问题时得到错误的答案
- 在C++的两个字符串中连接以逗号分隔的唯一值
- 如何修复valgrind启动时的致命错误(与libc6-dbg和libc6-dbg:i386连接)
- C++应用程序 MySQL odbc 数据库连接错误:在引发"otl_tmpl_exception<>"实例后终止调用
- OSX蓝牙打开RFCOMMChannelAsync声称已连接,但未建立连接,并且从未调用过委托
- 在 libcurl 连接池中预创建连接
- 套接字连接"Operation not permitted"错误,甚至使用升压/平发器根.cpp
- libcurl 和 DNS ttl 中的内部连接管理
- 如何应用 libcurl 的持久连接选项
- 提升 ASIO - io_service 不要等待连接到线程
- WinSock2:connect() 提供"连接被拒绝"
- 升压信号2将插槽传递到成员功能以断开连接