Rev 249 |
Blame |
Compare with Previous |
Last modification |
View Log
| Download
| RSS feed
#include "wmithread.h"
WmiThread::WmiThread(QObject *parent) :
QThread(parent)
{
// woker.moveToThread(this);
mutex.lock();
stopped = false;
mutex.unlock();
// connect(&process, SIGNAL(readyReadStandardOutput()), this, SLOT(readStandartProcessOutput()));
// connect(&process, SIGNAL(readyReadStandardError()), this, SLOT(readStandartProcessError()));
}
void WmiThread::run(){
QEventLoop loop; // = new QEventLoop();
Woker woker; // îáúåêò äëÿ ðàáîòû â òåëå ïîòîêà
// connect(&woker, SIGNAL(workEnd()), this, SLOT(wokerIsStopped()));
connect(&woker, SIGNAL(workEnd()), &loop, SLOT(quit()));
QString query_string;
// error = false; //ñáðîñèì ôëàã îøèáêè
query_string = tr("wmic -U ");
query_string.append(user_name);
query_string.append("%\"");
query_string.append(password);
query_string.append("\"");
query_string.append(tr(" //"));
query_string.append(host);
query_string.append(tr(" \""));
query_string.append(wmi_string);
query_string.append(tr("\""));
// process.start(query_string);
// process.start("ls\n");
// while (!stopped) {;}
qDebug() << query_string;
woker.setProcessString(query_string);
woker.startProcess();
loop.exec();
p_buffer = woker.workBuffer();
}
void WmiThread::stop(){
mutex.lock();
stopped = true;
mutex.unlock();
}
void WmiThread::readStandartProcessOutput(){
p_buffer = process.readAllStandardOutput();
qDebug() << QString(p_buffer);
mutex.lock();
stopped = true;
mutex.unlock();
process.close();
exit();
}
void WmiThread::readStandartProcessError(){
p_buffer = process.readAllStandardError();
error = true; // åñëè îøèáêà, óñòàíîâèì ôëàã îøèáêè âûïîëíåíèÿ WMI-çàïðîñà
}
/*
void WmiThread::wokerIsStopped(){
exit();
}
*/