Skip to the content.

QPing

Read this in other languages: English, :kr: 한국어

노트

설정 방법

HEADERS += QPing.h
SOURCES += QPing.cpp
#include <QtGlobal>
#include <QCoreApplication>
#include <QProcess>
#include <QtGlobal>
#include <QDebug>
#include <QFile>
#include <QSettings>
#include <QLocale>

#include <iostream>

#include "QPing.h"

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

    QString destIpAddress = "192.168.200.254";
    if ( argc == 2 )
    {
        // You can use application first parameter
        // For example) QPingSF 192.168.0.10
        QString strArg = argv[1];
        destIpAddress = strArg;
    }

    // Define your OS and OS language.
    // See sample of *.ini for OS. (You can define your own INI file)
    // Please suggest strings that can be set in various languages and operating systems.

    QString iniFilePath;
    QString localSystemName = QLocale::system().name();
    /* Returns the language and country of this locale as a string of the form "language_country",
     * where language is a lowercase, two-letter ISO 639 language code,
     * and country is an uppercase, two- or three-letter ISO 3166 country code.
    */
    QString langaugeISO639 = localSystemName.left(2);

#ifdef Q_OS_WIN

    if ( langaugeISO639 == "ko" )
    {
        iniFilePath = ":/ping-config-win-kr.ini"; // Windows, Korean
    }

    if ( langaugeISO639 == "en" )
    {
        iniFilePath = ":/ping-config-win-en.ini"; // Windows, English
    }

    /* TODO:
     * Create a new INI file for your native language, referencing an existing INI file.
    */

#endif

#ifdef Q_OS_LINUX

    if ( langaugeISO639 == "en" )
    {
        iniFilePath = ":/ping-config-linux-en.ini"; // Linux, English
    }

    /* TODO:
     * Create a new INI file for your native language, referencing an existing INI file.
    */

#endif

#ifdef Q_OS_MAC

    if ( langaugeISO639 == "en" ) // Mac, English
    {
        // iniFilePath = mac ini... I don't have a Mac, because I'm poor.
    }

    /* TODO:
     * Create a new INI file for your native language, referencing an existing INI file.
    */

#endif

    ////////////////////

    QPing qp; // main class

    qp.setIniFile( iniFilePath ); // set configuration file
    if ( ! qp.loadIniFile() )
    {
        std::cout <<  "[ERROR] Failed to load ini file" << std::endl;
        return (-1);
    }

    // Ping!
    QPing::pingResult result = qp.ping(destIpAddress);

    switch( result )
    {
        case QPing::pingSuccess:
            std::cout <<  "[SUCCESS] Success to ping" << std::endl;
        break;

        case QPing::pingFailed:
            std::cout <<  "[FAILED] Failed to ping" << std::endl;
        break;

        case QPing::initFailed1: // "success string is empty"
        case QPing::initFailed2: // "failed string is empty"
            std::cout <<  "[ERROR] Initialization is failed" << std::endl;
        break;

        case QPing::notFound: // something wrong
            std::cout <<  "[ERROR] Result is not found" << std::endl;
        break;

        default:
            std::cout <<  "[ERROR] Undefined result : " << ((quint32)result) << std::endl;
        break;
    }

    return 0;
}

라이센스

문의