#include "pingstring.h"#include <QProcess>PingString::PingString(){ mProcess = 0;}void PingString::takeOutput(){ QString *output = new QString(mProcess->readAllStandardOutput()); mProcess->kill(); //delete mProcess; bool result = false; if(output->contains("TTL")) result = true; delete output; emit pingResult(result);}void PingString::pingAdress(const QString &text){ mProcess = new QProcess; connect(mProcess, SIGNAL(readyReadStandardOutput()), this, SLOT(takeOutput())); mProcess->start("cmd /C ping "+(text));}
#include "iplistiterator.h"#include <QTreeWidget>#include <QTreeWidgetItemIterator>IplistIterator::IplistIterator(QTreeWidget *pTree, QObject *parent) : QObject(parent){ tree = pTree; iterator = new QTreeWidgetItemIterator(tree, QTreeWidgetItemIterator::All);}void IplistIterator::finalize(bool result){ /* Заморочки с базой и.т.п. будут здесь */ if(result) (**iterator)->setText(1, "OK!"); else (**iterator)->setText(1, "FAIL :("); ++(*iterator); if(!(**iterator)) { delete iterator; iterator = new QTreeWidgetItemIterator(tree, QTreeWidgetItemIterator::All); } emit nextPlease((**iterator)->text(0));}void IplistIterator::start(){ emit nextPlease((**iterator)->text(0));}
#include "pingthread.h"#include "iplistiterator.h"#include "pingstring.h"#include <QThread>#include <QTreeWidget>PingThread::PingThread(QTreeWidget *pTree){ tree = pTree;}void PingThread::run(){ PingString *pingString = new PingString; IplistIterator *iplistIterator = new IplistIterator(tree); connect(pingString, SIGNAL(pingResult(bool)), iplistIterator, SLOT(finalize(bool))); connect(iplistIterator, SIGNAL(nextPlease(const QString &)), pingString, SLOT(pingAdress(const QString &))); iplistIterator->start(); exec();}
IplistIterator *iplistIterator = new IplistIterator(tree, this);
IplistIterator::IplistIterator(QTreeWidget *pTree, QObject *parent) : QObject(parent){ tree = pTree; iterator = new QTreeWidgetItemIterator(tree, QTreeWidgetItemIterator::All);}void IplistIterator::finalize(bool result){ /* Заморочки с базой и.т.п. будут здесь */ if(result) (**iterator)->setIcon(0, QPixmap("./Resources/OK.jpg")); else (**iterator)->setIcon(0, QPixmap("./Resources/notOK.jpg")); ++(*iterator); if(!(**iterator)) { delete iterator; iterator = new QTreeWidgetItemIterator(tree, QTreeWidgetItemIterator::All); } parent()->sleep(3); emit nextPlease((**iterator)->text(0));}
(qobject_cast<PingThread *>(parent()))->sleep(3);
#include <QThread>#include <QTreeWidget>PingThread::PingThread(QTreeWidget *pTree){ tree = pTree;}void PingThread::run(){ PingString *pingString = new PingString; IplistIterator *iplistIterator = new IplistIterator(tree); connect(pingString, SIGNAL(pingResult(bool)), iplistIterator, SLOT(finalize(bool))); connect(iplistIterator, SIGNAL(nextPlease(const QString &)), this, SLOT(checkRequest(const QString &))); connect(this, SIGNAL(processNext(const QString &)), pingString, SLOT(pingAdress(const QString &))); iplistIterator->start(); exec();}void PingThread::checkRequest(const QString &text){ sleep(3); emit processNext(text);}