An activex control made by Qt axserver, for receiving UDP data



  • I made an activex control to receive UDP data, but readPendingDatagrams can not be called.
    This code works in exe project.

    ActivexTest::ActivexTest(QWidget *parent) : QWidget(parent)
    {
    m_udpclient = new QUdpSocket(this);
    connect(m_udpclient, SIGNAL(readyRead()), this, SLOT(readPendingDatagrams()));
    m_udpclient->bind(4477);
    }

    void ActivexTest::readPendingDatagrams()
    {
    while (m_udpclient->hasPendingDatagrams())
    {
    QByteArray datagram;
    datagram.resize(m_udpclient->pendingDatagramSize());
    QHostAddress sender;
    quint16 senderPort;
    m_udpclient->readDatagram(datagram.data(), datagram.size(), &sender, &senderPort);
    }
    }

    So, I started a thread to receive UDP data, but readPendingDatagrams can be called only for the first time.

    void SocketThread::run()
    {
    m_udpclient = new QUdpSocket();
    connect(m_udpclient, SIGNAL(readyRead()), this, SLOT(readPendingDatagrams()), Qt::DirectConnection);
    m_udpclient->bind(m_port);
    this->exec();
    }

    void SocketThread::readPendingDatagrams()
    {
    while (m_udpclient->hasPendingDatagrams())
    {
    QByteArray datagram;
    datagram.resize(m_udpclient->pendingDatagramSize());
    QHostAddress sender;
    quint16 senderPort;
    m_udpclient->readDatagram(datagram.data(), datagram.size(), &sender, &senderPort);
    }
    }

    Is this Qt's bug? Or, what's wrong with my code? Thank you!



  • Qt version: qt-opensource-windows-x86-msvc2010-5.5.1
    OS: windows 7



  • No body can help?


  • Qt Champions 2016

    Hi
    This is a user forum and people are in different time zones so might take some days.
    Also ActiveX is a windows thing so it makes question a bit special.
    So I would give it some more time before losing hope :)



  • @zhangsi If you have an activeX control, then you're inside some other .exe file and probably there's no processing of Qt events/signals.
    Try calling QCoreApplication::processEvents()



  • @hskoglund Thank you for your suggestion, I will try it.



  • @hskoglund Yes, it works. Thank you very much!

    Resolution below:

    void SocketThread::run()
    {
    m_udpclient = new QUdpSocket();
    //connect(m_udpclient, SIGNAL(readyRead()), this, SLOT(readPendingDatagrams()), Qt::DirectConnection);
    m_udpclient->bind(m_port);
    while (1)
    {
    if (m_stop) break;
    readPendingDatagrams();
    msleep(1);
    }
    //this->exec();

    }

    void SocketThread::readPendingDatagrams()
    {
    while (m_udpclient->hasPendingDatagrams())
    {
    QByteArray datagram;
    datagram.resize(m_udpclient->pendingDatagramSize());
    QHostAddress sender;
    quint16 senderPort;
    m_udpclient->readDatagram(datagram.data(), datagram.size(), &sender, &senderPort);
    }
    }

    It seems that signal/slot can not work well in axserver projects.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.