Results 1 to 6 of 6

Thread: Determine the Process ID

  1. #1
    Join Date
    Jan 2006
    Location
    Edmonton, Canada
    Posts
    101
    Thanks
    13
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Determine the Process ID

    Here's a (hopefully) quick question for you: how can I determine the process ID of my Qt application. I'm using Qt 4.2 on WindowsXP. I don't see any way to do this using Qt, so I'd expect there's some Windows-specific way to do it.

    Thanks

    Jimmy

  2. #2
    Join Date
    Jan 2006
    Location
    Edmonton, Canada
    Posts
    101
    Thanks
    13
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Determine the Process ID

    Hmmm.... I suppose the Win32 function "GetCurrentProcessId()" might help... duh....

  3. #3
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    554
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Determine the Process ID

    Why not use QProcess:id () ?

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Determine the Process ID

    Quote Originally Posted by ChristianEhrlicher View Post
    Why not use QProcess:id () ?
    This applies only for running instances of QProcess.

  5. #5
    Join Date
    Mar 2008
    Posts
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Determine the Process ID

    May be for your current process you can also use the static function: qint64 QCoreApplication::applicationPid ()

  6. #6
    Join Date
    Jan 2011
    Location
    Gordion
    Posts
    52
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Determine the Process ID

    (For Windows Only)I was need to, and find solution. You can get other informations that i wrote below, from tlhelp32.h
    It prints info about running process, not services!
    http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx

    Qt Code:
    1. typedef struct tagPROCESSENTRY32W {
    2. DWORD dwSize;
    3. DWORD cntUsage;
    4. DWORD th32ProcessID;
    5. DWORD th32DefaultHeapID;
    6. DWORD th32ModuleID;
    7. DWORD cntThreads;
    8. DWORD th32ParentProcessID;
    9. LONG pcPriClassBase;
    10. DWORD dwFlags;
    11. WCHAR szExeFile[MAX_PATH];
    12. } PROCESSENTRY32W,*PPROCESSENTRY32W,*LPPROCESSENTRY32W;
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. //in header
    2. #include <tlhelp32.h>
    3. #include <stdio.h>
    4.  
    5.  
    6. //in Qt source
    7. void MainWindow::getProcList()
    8. {
    9. BOOL bResult;
    10. PROCESSENTRY32 processInfo = {sizeof(PROCESSENTRY32)};
    11. HANDLE hSnapShot;
    12. hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
    13. bResult = Process32First(hSnapShot, &processInfo);
    14. while(bResult) {
    15. wprintf(L"Name: %s - SysProcId: %d \n", processInfo.szExeFile,processInfo.th32ProcessID);
    16. bResult = Process32Next(hSnapShot, &processInfo);
    17. }
    18. CloseHandle(hSnapShot);
    19. }
    To copy to clipboard, switch view to plain text mode 

    Best Regards.

Similar Threads

  1. Send a key to process
    By Nyphel in forum Qt Programming
    Replies: 2
    Last Post: 9th July 2007, 18:37
  2. problems starting process
    By parsito in forum Qt Programming
    Replies: 8
    Last Post: 11th May 2007, 22:32
  3. Replies: 3
    Last Post: 16th November 2006, 13:24
  4. Replies: 2
    Last Post: 26th April 2006, 11:43
  5. How to activate another process?
    By gtthang in forum Qt Programming
    Replies: 6
    Last Post: 3rd February 2006, 08:53

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.