Giter Site home page Giter Site logo

qprocesswatcher's Introduction

QProcessWatcher

Simple interface for monitoring state of process for Windows.

Use addProcess() method for add a process for monitoring by passing a case insensitive process name.

The signal processStarted() will be emitted in two cases:

  1. If the monitored process is already started before calling addProcess() method.
  2. When the first copy of process is started.

The signal processFinished() will be emitted when all copies of monitored process is closed.

You can define a PROCESS_WATCHER_DEBUG macro in project file for view a small debug information:

DEFINES += PROCESS_WATCHER_DEBUG

Usage

#include "qprocesswatcher.h"
...
QProcessWatcher watcher;
watcher.addProcess("MSPaint.exe");

Examples

Example 1

#include <QApplication>
#include <QWidget>
#include "qprocesswatcher.h"

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    // Create widget
    QWidget w;

    // Create watcher and add monitoring for "MSPaint.exe" process
    QProcessWatcher watcher;
    watcher.addProcess("MSPaint.exe");

    // Connect signals
    QObject::connect(&watcher, SIGNAL(processStarted(QString,QString)), &w, SLOT(show()));
    QObject::connect(&watcher, SIGNAL(processFinished(QString)), &w, SLOT(close()));

    return a.exec();
}

This windget-based application wait for starting "MSPaint.exe" process and then shows the Widget form.
Widget has closed automatically when "MSPaint.exe" is closed.

Example 2

#include <QApplication>
#include <QMessageBox>
#include "qprocesswatcher.h"

void onProcessStarted(const QString &processName,
                      const QString &originalProcessName)
{
    const QString title = QObject::tr("Process started");
    const QString message = QObject::tr("Process `%1` is started with name `%2`!")
            .arg(processName)
            .arg(originalProcessName);

    QMessageBox::information(nullptr, title, message);
}

void onProcessFinished(const QString &processName)
{
    const QString title = QObject::tr("Process finished");
    const QString message = QObject::tr("Process `%1` is finished!")
            .arg(processName);

    QMessageBox::information(nullptr, title, message);
}

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    a.setQuitOnLastWindowClosed(false);

    QProcessWatcher watcher;
    watcher.addProcess("MSPaint.exe");
    watcher.addProcess("CMD.EXE");

    QObject::connect(&watcher, &QProcessWatcher::processStarted, &onProcessStarted);
    QObject::connect(&watcher, &QProcessWatcher::processFinished, &onProcessFinished);

    return a.exec();
}

This application shows information message when processes "MSPaint.exe" and "CMD.EXE" starts or finished.

cmd.exe

qprocesswatcher's People

Contributors

wxmaper avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.