QUdpSocket receive Datagram into QtConcurrent
-
@JonB said in QUdpSocket receive Datagram into QtConcurrent:
Comment out your qDebug() for each datagram
correct - printing so much data to the windows console will not work, no matter if it's C++, C#, Java or whatever. The windows console is painful slow.
-
@LudoFR
I said earlier I don't know where your window is freezing. Let's find out whetherReceiveUdpPackage()
is being run thousands of times per second? Comment out yourqDebug()
for each datagram, we don't want thousands per seconds debug output. Put in a member variable to count the total number of times and debug it out occasionally. Are we indeed talking about thousands per second?@JonB Thanks again for your help, well its seems your right, without qDebug(), my GUI is not freezed, I have try with a delay of 50 and 100ms.
I will be careful next time with how I use the qDebug(), good to know.
Didn't think about that because never has any problem with my console output who usually are really fast. (Used only for debuging of course).
Now I will try Databing in my GUI and IO cards communication for check if this 50/100ms delay do not affect smoothest for our drivers.
Thanks a lot @JonB for your help, your professionalism and all this informations.
-
@JonB Thanks again for your help, well its seems your right, without qDebug(), my GUI is not freezed, I have try with a delay of 50 and 100ms.
I will be careful next time with how I use the qDebug(), good to know.
Didn't think about that because never has any problem with my console output who usually are really fast. (Used only for debuging of course).
Now I will try Databing in my GUI and IO cards communication for check if this 50/100ms delay do not affect smoothest for our drivers.
Thanks a lot @JonB for your help, your professionalism and all this informations.
-
@LudoFR
I am interested to learn: if you have put it some counter for each datagram received instead, are you indeed seeing 13,000-odd per second? -
For one second exactly (No delay) :
QT receive counter : 4602.
VS sender counter : 4565For 10 seconds exactly (No delay):
QT : 129278
VS: 129234 -
For one second exactly (No delay) :
QT receive counter : 4602.
VS sender counter : 4565For 10 seconds exactly (No delay):
QT : 129278
VS: 129234 -
@LudoFR
Well, firstly looks like VS & Qt are similar, which is good news. Secondly surprised it seems receiver is receiving more than sent? I don't think each side agrees on exactly what 1 second is :D@JonB said in QUdpSocket receive Datagram into QtConcurrent:
Secondly surprised it seems receiver is receiving more than sent?
@JonB Thanks god I'm not the only one...
@JonB said in QUdpSocket receive Datagram into QtConcurrent:
I don't think each side agrees on exactly what 1 second is :D
Science....is not an exact science... did performance computer impact that kind of information? Sender is an Asus Rog Strix3 with a config lower than my PC
-
Hello everyone,
Still learning on Qt, and I try to run a QUdpSocket receiving UDP data into a QtConcurrent thread, for avoiding GUI freezing.
Here my main.cpp
If i call "testComThread()" my function work and I receive my data, but if i call "QtConcurrent::run(testComThread);" I dont see any data into my console and my breakpoint in my "while" is never reached.
Did I need to call a kind of dispatcher or something maybe? This is my first use of QtConcurrent. Thanks in advance.
#include <QGuiApplication> #include <QQmlApplicationEngine> #include <Manage/variablesglobales.h> #include <Manage/communications.h> #include <QtConcurrent> void testComThread(); int main(int argc, char *argv[]) { #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); #endif QGuiApplication app(argc, argv); QQmlApplicationEngine engine; const QUrl url(QStringLiteral("qrc:/main.qml")); QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, &app, [url](QObject *obj, const QUrl &objUrl) { if (!obj && url == objUrl) QCoreApplication::exit(-1); }, Qt::QueuedConnection); engine.load(url); QFuture<void> test1 = QtConcurrent::run(testComThread); //testComThread(); return app.exec(); } void testComThread() { Communications* com = new Communications(); com->InitialiseConnection(); }
my communication.cpp
#include "communications.h" Communications::Communications(QObject *parent) : QObject(parent) { } void Communications::InitialiseConnection() { udpSock = new QUdpSocket(this); udpSock->bind(QHostAddress::Any,50003); connect(udpSock,&QUdpSocket::readyRead,this,&Communications::ReceiveUdpPackage); } void Communications::ReceiveUdpPackage() { QHostAddress sender; quint16 port; while (udpSock->hasPendingDatagrams()) { QByteArray datagram; datagram.resize(udpSock->pendingDatagramSize()); udpSock->readDatagram(datagram.data(),datagram.size(),&sender,&port); qDebug() <<"Message From :" << datagram.data(); } }
Thank you in advance.
@LudoFR said in QUdpSocket receive Datagram into QtConcurrent:
Hello everyone,
Still learning on Qt, and I try to run a QUdpSocket receiving UDP data into a QtConcurrent thread, for avoiding GUI freezing.
Here my main.cpp
If i call "testComThread()" my function work and I receive my data, but if i call "QtConcurrent::run(testComThread);" I dont see any data into my console and my breakpoint in my "while" is never reached.
Did I need to call a kind of dispatcher or something maybe? This is my first use of QtConcurrent. Thanks in advance.
Truncated code:
int main(int argc, char *argv[]) { QFuture<void> test1 = QtConcurrent::run(testComThread); return app.exec(); } void testComThread() { Communications* com = new Communications(); com->InitialiseConnection(); udpSock = new QUdpSocket(com); udpSock->bind(QHostAddress::Any,50003); connect(udpSock,&QUdpSocket::readyRead,this,&Communications::ReceiveUdpPackage); }
This won't work. QtConcurrent::run() runs a function in a thread that doesn't have an event loop, and may cease to exist when the invoked function returns.
Regarding QML: The language has fairly strong rules regarding capitalization. Types should begin with an upper case letter. Properties and functions should begin with a lower case letter. Following the convention in C++ will make integration easier.
-
@JonB said in QUdpSocket receive Datagram into QtConcurrent:
Secondly surprised it seems receiver is receiving more than sent?
@JonB Thanks god I'm not the only one...
@JonB said in QUdpSocket receive Datagram into QtConcurrent:
I don't think each side agrees on exactly what 1 second is :D
Science....is not an exact science... did performance computer impact that kind of information? Sender is an Asus Rog Strix3 with a config lower than my PC
-
@LudoFR said in QUdpSocket receive Datagram into QtConcurrent:
Hello everyone,
Still learning on Qt, and I try to run a QUdpSocket receiving UDP data into a QtConcurrent thread, for avoiding GUI freezing.
Here my main.cpp
If i call "testComThread()" my function work and I receive my data, but if i call "QtConcurrent::run(testComThread);" I dont see any data into my console and my breakpoint in my "while" is never reached.
Did I need to call a kind of dispatcher or something maybe? This is my first use of QtConcurrent. Thanks in advance.
Truncated code:
int main(int argc, char *argv[]) { QFuture<void> test1 = QtConcurrent::run(testComThread); return app.exec(); } void testComThread() { Communications* com = new Communications(); com->InitialiseConnection(); udpSock = new QUdpSocket(com); udpSock->bind(QHostAddress::Any,50003); connect(udpSock,&QUdpSocket::readyRead,this,&Communications::ReceiveUdpPackage); }
This won't work. QtConcurrent::run() runs a function in a thread that doesn't have an event loop, and may cease to exist when the invoked function returns.
Regarding QML: The language has fairly strong rules regarding capitalization. Types should begin with an upper case letter. Properties and functions should begin with a lower case letter. Following the convention in C++ will make integration easier.
@jeremy_k said in QUdpSocket receive Datagram into QtConcurrent:
Regarding QML: The language has fairly strong rules regarding capitalization. Types should begin with an upper case letter. Properties and functions should begin with a lower case letter. Following the convention in C++ will make integration easier.
Agreed and thanks, but i need to make a choice for my compagny and our futur tools, C++, python, Qt, PyCharm, VS.. first I check the language, the possibilities, time to develop with, the compatibily with all the dependency we need...
After our choice, I will check about the code convention, and use it in the final project, hope you have remarked this is not a real project !
But it's clearly not my priority now....