• 12591阅读
  • 0回复

QSocketNotifier: socket notifiers cannot be enabled from another thread [复制链接]

上一主题 下一主题
离线jasonjoy
 
只看楼主 倒序阅读 楼主  发表于: 2009-11-05
— 本帖被 XChinux 从 General Qt Programming 移动到本区(2011-01-02) —
这个问题应该怎么解决呢?我的代码如下:
void ReceiveThread::run()
{          
        initSocket();

    exec();
}

void ReceiveThread::initSocket()
{
        udpSocket=new QUdpSocket;

        udpSocket->bind(QHostAddress::LocalHost,5001);

        connect(udpSocket,SIGNAL(readyRead()),this,SLOT(receiveDatagram()));
}

void ReceiveThread::receiveDatagram()
{
        while(udpSocket->hasPendingDatagrams())
        {
                QByteArray datagram;
                QHostAddress senderAddress;
                quint16 port;
                datagram.resize(udpSocket->pendingDatagramSize());
                udpSocket->readDatagram(datagram.data(),datagram.size(),
                                &senderAddress,&port);
                QString str(datagram);

                emit deliverReceivedDatagram(str,addUeTimes);
        }
}
快速回复
限100 字节
 
上一个 下一个