Results 1 to 10 of 10

Thread: QProcess to get CPU state

  1. #1
    Join Date
    Nov 2010
    Posts
    9
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QProcess to get CPU state

    Hi,

    i want show in my Qt Application the CPU state. So, i do:

    . Create a script ( top -n 1 | grep Cpu | awk '{print $2}' ):
    . when i execute the script in shell, i get ( for example): 5.9%us,

    . In Qt, i create a QProcess when to get the CPU state:
    . process->start("/home/script");

    I receive Started() and finished(int, Qprocess::ExisStatus) Signals, but not the Signal readyReadStandardOutput() .





    So, if when i execute the script in shell i get some output, when i execute process in Qt i should get outuput ??

    To check if i was implement my process correct in Qt, i change my script to: (ls -lA), and in Qt i get a list of files as i execute the script in terminal.


    Can anyone help me to fix this problem??

    Thanks, Sergio Silva

  2. #2
    Join Date
    Jul 2011
    Location
    Italy
    Posts
    24
    Thanks
    2
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QProcess to get CPU state

    Don't use pipe:
    http://lists.trolltech.com/qt-intere.../msg00049.html

    EDIT: Sorry, I did't read you're using a script.
    Last edited by sakya; 10th August 2011 at 14:12.

  3. #3
    Join Date
    Nov 2010
    Posts
    9
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QProcess to get CPU state

    hi, after return from vacation...

    when the process was implemented i searched an read that were some problems with pipe, so i did a scipt.


    Can anyone help me to fix this problem??

    Thanks, Sergio Silva

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QProcess to get CPU state

    Does your script contain a shebang? Which interpreter?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Nov 2010
    Posts
    9
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QProcess to get CPU state

    Quote Originally Posted by wysota View Post
    Does your script contain a shebang? Which interpreter?
    My script contains the following: top -n 1 | grep Cpu | awk '{print $2}'
    and it is a plain text document with permissions to all users.

    As i said in first message, when i open a shell and execute the script, the output is: 4.8%us, (for example).

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QProcess to get CPU state

    Well, here you miss one important step of the process -- you are not opening a shell. That's why I'm asking about a shebang.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Nov 2010
    Posts
    9
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QProcess to get CPU state

    wysota,

    i did not know which was a shebang before you talk about it

    so, after learn what is and what does, i change my script.
    Now my script have:
    #!/bin/bash
    top -n 1 | grep Cpu | awk '{print $2}'

    but unfortunately still doesn't work.

  8. #8
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QProcess to get CPU state

    What happens if you give top the 'b' switch?

    top -nb 1 | grep Cpu | awk '{print $2}'

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

    sergiofil (27th August 2011)

  10. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QProcess to get CPU state

    Quote Originally Posted by sergiofil View Post
    wysota,

    i did not know which was a shebang before you talk about it

    so, after learn what is and what does, i change my script.
    Now my script have:
    #!/bin/bash
    top -n 1 | grep Cpu | awk '{print $2}'

    but unfortunately still doesn't work.
    It will not work, top requires a tty when ran like this (see output on stderr).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. The following user says thank you to wysota for this useful post:

    sergiofil (27th August 2011)

  12. #10
    Join Date
    Nov 2010
    Posts
    9
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QProcess to get CPU state

    Quote Originally Posted by SixDegrees View Post
    What happens if you give top the 'b' switch?

    top -nb 1 | grep Cpu | awk '{print $2}'
    i out b parameter:

    #!/bin/bash
    top -b -n 1 | grep Cpu | awk '{print $2}'

    and it WORKS!!!

    Thanks SixDegrees and wysota for help!

Similar Threads

  1. State Machine returning to previous state
    By akiross in forum Qt Programming
    Replies: 2
    Last Post: 10th May 2011, 00:39
  2. Replies: 0
    Last Post: 19th December 2010, 16:03
  3. Replies: 0
    Last Post: 26th August 2010, 10:44
  4. Replies: 3
    Last Post: 7th August 2010, 15:12
  5. QProcess state
    By patcito in forum Qt Programming
    Replies: 1
    Last Post: 17th January 2006, 19:56

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.