Qt application not responding
-
Hey,
I have created an application for network monitor using Qt and Winpcap.
The application is running in while loop and after 5 sec from start appears in the title bar "application not responding". Here is an image.
-
Hi
Well if it stays in the loop, it will strangulate the event loop.
Are you sure it leaves the while loop once in a while? -
I often use this line on a loop to keep my application alive :
qApp->processEvents();
Give it a try !
-
Hi
Well if it stays in the loop, it will strangulate the event loop.
Are you sure it leaves the while loop once in a while?@mrjj said in Qt application not responding:
Hi
Well if it stays in the loop, it will strangulate the event loop.
Are you sure it leaves the while loop once in a while?Yes @mrjj ...the last line packageUpdate::processPackage() is a function where i make a switch and depending on the package type are called other function like printICMP, printTCP, print UDP s.a.m.d. And again every function (printICMP, printTCP, print UDP) call other functions like printIPHeader, print EthernetHeade. In every function, I print a message with QDebug and messages are displayed.
Also for each package, i print the output in a text file and it works...all data is in that file. The only problem is with the interface.[UPDATE 1] I also tried to run the while loop on a new thread and the result is the same.
-
@mrjj said in Qt application not responding:
Hi
Well if it stays in the loop, it will strangulate the event loop.
Are you sure it leaves the while loop once in a while?Yes @mrjj ...the last line packageUpdate::processPackage() is a function where i make a switch and depending on the package type are called other function like printICMP, printTCP, print UDP s.a.m.d. And again every function (printICMP, printTCP, print UDP) call other functions like printIPHeader, print EthernetHeade. In every function, I print a message with QDebug and messages are displayed.
Also for each package, i print the output in a text file and it works...all data is in that file. The only problem is with the interface.[UPDATE 1] I also tried to run the while loop on a new thread and the result is the same.
@Adrian.Aioanei As @mrjj said you're blocking the event loop while you're in that while loop (all that prints will work as they don't depend on event loop but UI will not). To check whether this loop is the problem put
qApp->processEvents();
in your while loop as @jsavin suggested. If this helps you should think about moving this long lasting operation (the while loop) to a separate thread.
-
@jsulm said in Qt application not responding:
@Adrian.Aioanei As @mrjj said you're blocking the event loop while you're in that while loop (all that prints will work as they don't depend on event loop but UI will not). To check whether this loop is the problem put
qApp->processEvents();
in your while loop as @jsavin suggested. If this helps you should think about moving this long lasting operation (the while loop) to a separate thread.
What type of object is qApp? In main the type is resolved but in my class doesn't know what type is qApp.
-
@jsulm said in Qt application not responding:
@Adrian.Aioanei As @mrjj said you're blocking the event loop while you're in that while loop (all that prints will work as they don't depend on event loop but UI will not). To check whether this loop is the problem put
qApp->processEvents();
in your while loop as @jsavin suggested. If this helps you should think about moving this long lasting operation (the while loop) to a separate thread.
What type of object is qApp? In main the type is resolved but in my class doesn't know what type is qApp.
@Adrian.Aioanei qApp is a macro. Include qapplication header file.
See http://doc.qt.io/qt-5/qapplication.html -
Thanks @jsulm .
I have made some changes and now I run the entire loop in a new thread and works perfectly.