There was a question from a beginner. I want to perform my functions - read and parse the file. Wrote the code:

int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; w.show(); MyServer server; f1(); f2(); return a.exec(); } 

When I execute this code, the functions work only 1 time, then the transition to exec follows, and everything stops. In this case, an instance of the class MyServer (works with a socket) - works and accepts data, writes them to a file. And I need them to run cyclically.

How to be? I feel my functions need to be arranged in a class and use it, but maybe there is some other way?

  • Wrap your functions in a loop? - Vladimir Martyanov
  • Yes. There the functions are to read the file, parse the data, display the data and update the graph. And they are executed cyclically, but still receiving data from the socket. - Alex Sh
  • Well, wrap, if yes :-) - Vladimir Martyanov

1 answer 1

Example

You need to create a timer object, and in the handler to work with the socket.

  • Those. can I create several timers and in them, when the timer triggers, perform my functions? - Alex Sh
  • Of course, at different intervals. - HasmikGaryaka
  • If the data goes to the socket every 2 seconds, then the timer should be run for 2s? No data loss? Data 15 variables, type int. - Alex Sh
  • If the function has time to execute in 2 seconds, exactly 2 seconds after the start of the first one, it will start again. - HasmikGaryaka
  • Can timers work in parallel? - Alex Sh