Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. An activex control made by Qt axserver, for receiving UDP data
Qt 6.11 is out! See what's new in the release blog

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

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 3.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    zhangsi
    wrote on last edited by
    #1

    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!

    1 Reply Last reply
    0
    • Z Offline
      Z Offline
      zhangsi
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • Z Offline
        Z Offline
        zhangsi
        wrote on last edited by
        #3

        No body can help?

        hskoglundH 1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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 :)

          1 Reply Last reply
          1
          • Z zhangsi

            No body can help?

            hskoglundH Offline
            hskoglundH Offline
            hskoglund
            wrote on last edited by
            #5

            @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()

            Z 2 Replies Last reply
            3
            • hskoglundH hskoglund

              @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()

              Z Offline
              Z Offline
              zhangsi
              wrote on last edited by
              #6

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

              1 Reply Last reply
              0
              • hskoglundH hskoglund

                @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()

                Z Offline
                Z Offline
                zhangsi
                wrote on last edited by
                #7

                @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.

                1 Reply Last reply
                1

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved