Solved 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.
-
@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 -
@LudoFR
You don't really need a timer. This will do, presumably:udpSock->readDatagram(datagram.data(),datagram.size(),&sender,&port); memberCounter++; if (memberCounter % 10000 == 0) qDebug() <<"memberCounter:" << memberCounter;
-
@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
-
@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.
-
@LudoFR
Don't worry about exact timings. Your 10 second timing indicates there are around 13,000 datagrams per second, which is just what you were originally expecting. Just make sure whatever processing you do on those datagrams is fast! -
@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....