- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我得到错误:
QIODevice::write (QTcpSocket): device not open. After trying , I think problem is passing parameter server->nextPendingConnection() into object. Can someone has idea how to do it correctly?
我的理解是 socketClient
的对象未正确初始化。我正在使用带有 Qt 的 Ubuntu。
我正在使用 Qt 实现服务器。服务器部分有两个基于QTcpServer
和QTcpSocket
的类。说 Server
和 SocketClient
。我正在服务器中创建 SocketClient 对象,出于测试目的,我打开了 telnet session 并希望看到该服务器在终端上写“hello”。但不知何故它不起作用。有人可以告诉我哪里出错了。
Server::Server(QObject *parent) : QObject(parent)
{
server_obj = new QTcpServer( this );
}
void Server::startServer()
{
connect( server_obj, SIGNAL( newConnection() ), this, SLOT( incomingConnection() ) );
if( !server_obj->listen( QHostAddress::Any, 9999) )
{
qDebug() << " Server failed to get started";
}
else
{
qDebug() << " Server started"; // this is successful
}
}
void Server::incomingConnection()
{
socketforClient = new SockClient( server_obj->nextPendingConnection() );// has a doubt on nextPendingconection??
//only for testing remove it
socketforClient->writeToClient();
}
客户类
* Description: Its a constructor.I have changed default constructor to add QTcpSocket* object in parameter.I used this constructor in void Server::incomingConnection()
*/
SockClient::SockClient(QObject *parent,QTcpSocket* socket ) : QObject(parent)
{
socketClient = new QTcpSocket( socket );
qDebug() << " we are in constructor of 1st sockclient ";
}
// this is for testing purpose only
void SockClient::writeToClient()
{
socketClient->write(" hello world\r\n");
socketClient->flush();
socketClient->waitForBytesWritten(3000);
}
//SockClient的头文件
class SockClient : public QObject
{
Q_OBJECT
public:
explicit SockClient( QObject *parent, QTcpSocket* socket= 0 ); // I have created
void writeToClient(); // This is for testing purpose
~SockClient();
signals:
private slots:
void readClient();
private:
void sendResponsetoMops();
QTcpSocket *socketClient;
quint16 nextBlockSize;
public slots:
};
最佳答案
您使用:
socketClient = new QTcpSocket( socket );
尝试改用下面的代码:
socketClient = socket;
并使用 socketforClient = new SockClient(this, server->nextPendingConnection() );
代替
socketforClient = new SockClient( server->nextPendingConnection() );
关于c++ - 设备未打开错误 + QIODevice::write,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31815655/
我想从 QIODevice 继承子类,因为我正在创建我的自定义设备(自定义串行端口对象)。 我看到了: writeData(const char *, qint64 ) : qint64 readDa
我需要一个文件的校验和并找到this ,效果很好。现在我想更改此函数以获取指向之前已使用以下行打开的 QIODevice 的指针: if (!file.open(QFile::ReadOnly | Q
软呢帽上的 qt5.7 检查了这个audio-to-chart example并发现 QIODevice::writeData 用于读取麦克风输入。由于它有效并且正在绘制来自麦克风的数据,因此该功能显
我正在使用 qt 5.3。 我有一个很大的东西写入 QIODevice 以供读取。我想要一个代理来获取数据,同时让 QIODevice 中的数据可供其他东西读取。因此,如果我调用 readAll(),
我试图从文件中读取并放入文本编辑中,但它一直说 QIODevice::read:device not open。 .txt 文件与我的 .qrc 和 .cpp 文件位于同一位置。我正在按照网上的分步指
我得到错误: QIODevice::write (QTcpSocket): device not open. After trying , I think problem is passing par
我想使用 QMediaPlayer 制作音频流程序(如电话) , QAudioProbe和 QAudioOutput Qt 5.3.0 MSVC2012 OpenGL 32 位中的类。 这是我的代码:
我正在尝试将所有传出的 POST 数据保存在 QtWebKit 中。 我使用覆盖 来做到这一点QNetworkReply *QNetworkAccessManager::createRequest(O
Qt 5.7 根据文档,QAudioDecoder不支持流媒体。但它接受文件名或 QIODevice 作为源。出现了“好主意”:让我们子类化 QIODevice 来创建流媒体支持。 但我总是收到错误:
我想使用一些标准的QUdpSocket 方法,确切地说是read() 和readAll()。所以,根据QUdpSocket的文档: If you want to use the standard QI
如果我想将数据写入远程端并等待它的响应,我至少需要一个waitForReadyRead。但在调用它之前,我是否需要使用 waitForBytesWritten 手动刷新输出队列,或者 Qt 会自动为我
我正在尝试为实时音频应用程序实现双缓冲区,QAudioInput 要求它是QIODevice 的子类。我发现此方法的文档非常困惑。 首先,文档中的方法签名与 QT 5.9.2 的 header 不匹配
我正在对 QIODevice 类进行子类化,以通过 QAudioInput 和 QAudioOutput 实例编写和读取语音。但是当我用耳机读它时,声音几乎每隔几毫秒就会中断一次。它发出的声音非常糟糕
我尝试在 docker 容器中构建应用程序。 如果我在我的主机上构建这个镜像,一切顺利。如果我将它推送到 git,hub.docker 会在构建日志中显示以下错误: Step 12/22 : RUN
我是 Qt 的新手,我正在学习它的 Getting Started页。我想知道以下语句是什么意思,为什么需要它们? 在打开功能中: if (!file.open(QIODevice::ReadOnly
我正在编写基于 QCoreApplication 的控制台应用程序,我想在用户向标准输入输入内容时获取信号(一次整行或按字符输入,这对我的应用程序并不重要) . QFile 根据文档不发出信号,所以如
我正在尝试在 PySide 中子类化 QFile 以实现自定义读取行为。但是,如下面的简化代码所示,即使子类的 readData 实现只是调用了父类的 readData 函数,返回的数据也是不正确的。
我希望我的 QT 应用程序将某些日志存储在不同的文件中。我一直在使用 qDebug() open(QIODevice::WriteOnly|QIODevice::Append)){ // Th
当我编译我的程序时,我收到错误消息“QIODevice::write: device not open”这个程序在我的旧电脑上运行但由于某种原因它在我的新电脑上不运行。非常感谢任何有关如何修复此错误的
Qt 4.8 documentation包含以下建议: If you want to use the standard QIODevice functions read(), readLine(),
我是一名优秀的程序员,十分优秀!