Results 1 to 9 of 9

Thread: signals and events queued...

  1. #1
    Join Date
    Jan 2006
    Location
    germany
    Posts
    75
    Thanks
    9
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default signals and events queued...

    i am reading output from a process and printing it in a textedit, but the text is printed in big blocks every once in while instead of being added line-by-line continuously.

    a model of this operation would look like this:

    1. obect1(qthread) posts event with on line to base object
    2. base object receives event and emits string as a signal
    3. slot in gui object receives signal and appends the passed string to the textedit

    i tried using QApplication::sendPostedEvents(); every three lines in object1(the thread) but that locks up the thread.
    then i tried using kapp->processEvents(); in the gui thread everytime the slot receives a line (because i thought that maybe only the redraws of the textedit are queued), but then the whole app freezes
    any ideas?

    thanks!
    Quote Originally Posted by Bertolt Brecht
    What is the robbing of a bank compared to the founding of a bank?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: signals and events queued...

    Quote Originally Posted by soul_rebel
    i am reading output from a process
    What do you mean by "process"? An external program or some activity within your application?

  3. #3
    Join Date
    Jan 2006
    Location
    germany
    Posts
    75
    Thanks
    9
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: signals and events queued...

    Quote Originally Posted by jacek
    What do you mean by "process"?
    it is a unix io-pipe that runs a command that produces output
    Quote Originally Posted by Bertolt Brecht
    What is the robbing of a bank compared to the founding of a bank?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: signals and events queued...

    Quote Originally Posted by soul_rebel
    it is a unix io-pipe that runs a command that produces output
    Then maybe the data is buffered by this pipe? How often does that thread post events?

  5. #5
    Join Date
    Jan 2006
    Location
    germany
    Posts
    75
    Thanks
    9
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: signals and events queued...

    the thread posts an event with a single line as soon as that is available, which in my case means it posts events nearly all the time.
    Quote Originally Posted by Bertolt Brecht
    What is the robbing of a bank compared to the founding of a bank?

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: signals and events queued...

    Quote Originally Posted by soul_rebel
    the thread posts an event with a single line as soon as that is available, which in my case means it posts events nearly all the time.
    Have you checked that? Maybe it posts those events in bursts?

  7. #7
    Join Date
    Jan 2006
    Location
    germany
    Posts
    75
    Thanks
    9
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: signals and events queued...

    i am using kprocio instead of the unix io-pipe now and it is even worse.... i think i will just post some code:
    this is the relevant part of object 1
    Qt Code:
    1. activeProcs.append(proc.name());
    2.  
    3. proc.start(KProcess::OwnGroup, KProcess::All); /// ownGroup so children spawned by proc can be killed too + comm=alloutput
    4.  
    5. /// to prevent queueing of messages we start a timer
    6. QTimer *timer = new QTimer(this);
    7. connect( timer, SIGNAL(timeout()), this, SLOT(postAllEvents()) );
    8.  
    9. timer->start(2*1000);
    10.  
    11. while (proc.isRunning() || (proc.readln(Buffer) != -1))
    12. {
    13. /// the output will not be processed/interpreted by this call, but instead
    14. /// by the gui thread, because that has relevant information neede
    15.  
    16.  
    17. if (Buffer!="")
    18. {
    19. Buffer.remove('\n');
    20. Buffer.remove(QChar(13));
    21. qDebug("posting 1 event");
    22. QApplication::postEvent(this, new QCustomEvent((QEvent::Type)1200, new QString(Buffer))); /// signal it out
    23. }
    24.  
    25.  
    26. if (toBeStoppedProcs.contains(proc.name()) || toBeStoppedProcs.contains("*")) /// should be interrupted
    27. {
    28. proc.kill(SIGINT); /// try to terminate nicely
    29. if (!proc.wait(2))
    30. proc.kill(SIGKILL);/// then we kill it
    31.  
    32. Buffer = "--> Process interrupted by User."; /// get line from output and make it red
    33. QApplication::postEvent(this, new QCustomEvent((QEvent::Type)1201, new QString(Buffer))); /// signal it out
    34. }
    35.  
    36. Buffer = "";
    37. }
    38.  
    39. timer->stop();
    40. delete timer;
    41.  
    42. /// erase it from both lists
    43. activeProcs.erase(activeProcs.find(proc.name()));
    44. while (toBeStoppedProcs.contains(proc.name()))
    45. toBeStoppedProcs.erase(toBeStoppedProcs.find(proc.name()));
    46.  
    47. QApplication::postEvent(this, new QCustomEvent((QEvent::Type)1202, NULL)); /// signal it out
    To copy to clipboard, switch view to plain text mode 
    i have changed bahviuor so that a timer in the thread sendsallpostedevents every 2 seconds and i have a second timer in the gui class that calls processEvents() every 2 seconds.
    they are succesfully called (i have a qdebug message that tells me "sending events" and "processing events"every two seconds), but "posting one event" appears only in bursts often even only after the thread finished....
    what can i do about this? i thought sendpostedevents and processevents should prevent all qt-related event-queueing.
    thanks for you help
    Quote Originally Posted by Bertolt Brecht
    What is the robbing of a bank compared to the founding of a bank?

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: signals and events queued...

    Quote Originally Posted by soul_rebel
    while (proc.isRunning() || (proc.readln(Buffer) != -1))
    If the process is running, you will enter the loop without reading its output.

  9. The following user says thank you to jacek for this useful post:

    soul_rebel (12th May 2006)

  10. #9
    Join Date
    Jan 2006
    Location
    germany
    Posts
    75
    Thanks
    9
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: signals and events queued...

    thanks, i just realised that
    i thought || was and/or with all arguments being checked....
    Quote Originally Posted by Bertolt Brecht
    What is the robbing of a bank compared to the founding of a bank?

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.