- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在编写一个多线程服务器,但在“mythraed”类的编译过程中出现以下错误:1) 无法连接 (null)::readyRead() 到 mythread::readyRead()2) 无法连接 (null)::disconnected() 到 mythread::disconnected()我该如何解决?这是我的代码:
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(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);
}
此外,您不需要从文档中明确断开连接:
All signals to and from the object are automatically disconnected, and any pending posted events for the object are removed from the event queue. However, it is often safer to use deleteLater() rather than deleting a QObject subclass directly.
关于c++ - 错误:无法连接 (null)::readyRead() 到 mythread::readyRead(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34177913/
我正在编写一个多线程服务器,但在“mythraed”类的编译过程中出现以下错误:1) 无法连接 (null)::readyRead() 到 mythread::readyRead()2) 无法连接 (
我正在尝试编写一个小型 UDP 服务器应用程序。 我有一个客户端传输到这个应用程序套接字,我已经使用一个小的 UDP 回显程序(它将端口上接收到的数据回显到屏幕上)验证了它发送正常,而且,我可以看到在
我有一个相对粗糙的设备(两台计算机通过 COM 端口连接),我必须通过 QSerialPort 让它工作。这个想法很简单:数据将通过每个 COM 端口从一个组件发送到另一个组件。发射器工作正常,通过软
因此,我试图让我的 Arduino 与我的 Qt 项目进行通信,但信号 readyRead() 从未由 QSerialPort 发出。我试错了许多方法和命令来实现它,尝试了以下视频中的代码,但它也不起
我在 QByteArray 中从 RS232 接收字节时遇到问题。我连接了 readyread() 信号来调用我的串行端口方法,在其中我正在使用 readAll() 将字节读取到 QByteArray
我正在编写一个从套接字接收数据的 Qt/C++ 程序。我发现我丢失了 readyRead 信号,因为我的插槽分析传入数据的时间太长了。所以现在我已经将它配对到最低限度: void test::inpu
我有 QTcpServer。我想从客户端发送大数据以及如何在服务器接收到所有数据时捕获信号?“while (socket->bytesavailable)”不起作用。 例如: 当 qbytearray
我遇到了 QUdpSocket 的问题。信号 readyRead() 似乎从未发出过。因此,我决定创建 QTimer 并检查套接字读取队列的状态。这样我确保套接字正常工作(bytesAvailable
以下代码旨在显示通过网络发送的图像。我发送了一个 16 字节的 header ,我用它来计算后面的图像大小,然后读取那么多字节并显示图像。我在此链接中使用了这个概念 Tcp packets using
我正在尝试在本地 OSX 10.11 中启动 QLocalServer。 我有客户端尝试循环连接到服务器: int connect(const char* filename) { int sock
我正在尝试弄清楚如何正确使用 Qt TCP 套接字以及多线程。作为一个支持更复杂但类似的东西的测试项目,我想在未来尝试做以下事情:一个简单的应用程序,它要么只监听一个传入连接,要么连接到一个服务器套接
这是我在这个网站上的第一个问题! 我在从一个 COM 端口读取数据时遇到了一些问题,我从另一个 COM 端口发送了一条完整的消息,当我用 Qt 接收它时,它总是被分成多个子消息。 void Seria
当我运行以下命令时,为什么我永远不会得到 readyRead/readyReadStandardOutput/readyReadStandardError 信号?我在控制台中获得了所有输出。我正在使用
我刚刚遇到了来自 QUdpSocket 的 readyRead() 信号的困难时期,虽然我找到了一个解决方案,但我仍然不确定我做了什么,但我想更准确地了解我的解决方案为什么有效。这是我的情况: 我连接
我有一个 QTcpSocket,它位于与 GUI 不同的线程中。 当通过将 readyRead() 信号连接到某个插槽来使用它时,一切正常。但是当我不使用它并遇到一个条件控制的 while(condi
根据以下帖子,只有在当前正在执行的插槽完成后,才会提供发出的信号。 Wait for a SLOT to finish the execution with Qt 我有一个基于 ssl 套接字的客户端
使用 Qt(包括带有 MinGW 的 Windows)编写跨平台应用程序。为了从 SSL 套接字读取数据,我创建了一个单独的线程。这个线程存在是出于历史原因,因为早些时候该应用程序是使用 C 套接字/
我创建了一个 hello-world 程序来帮助我理解 QTcpServer 和 QTcpSocket 的工作原理。在其中,QTcpServer 接受新连接并将它们的 readyRead() 信号连接
我在 Raspberry Pi 上使用 qextserialport 与 PanStamp(Arduino 兼容设备)通信。 这个连接到 Pi 的 PanStamp 执行两个功能: 每秒发送一些传感器
当使用QTcpSocket接收数据时,使用的信号是readyRead(),表示有新数据可用。但是,当您在相应的插槽实现中读取数据时,不会发出额外的 readyRead()。这可能是有道理的,因为您已经
我是一名优秀的程序员,十分优秀!