C++ (Qt)#include "processtree.h"#include <QProcess> ProcessTree::ProcessTree( void ) : mProcess(0){} ProcessTree::~ProcessTree( void ) { delete mProcess;} // void ProcessTree::run() // не нужно перекрывать // пришел сигнал от запущенного процессаvoid ProcessTree::SlotReadProcess( void ){ assert(mProcess); QString output = mProcess->readAllStandardOutput()); delete mProcess; mProcess = 0; emit SignalReply(reply_Output, output); // ответили боссу} // пришла команда (от кто создал экземпляр ProcessTree) void ProcessTree::SlotCommand( int cmd, QString param ){ switch (cmd) { case cmd_GetStatus: if (mProcess) emit SignalReply(reply_Busy, "Waiting for process"); else emit SignalReply(reply_Ready, "Ready"); break; case cmd_RunProcess: if (mProcess) emit SignalReply(reply_Busy, "Waiting for process"); else { mProcess = new QProcess(); connect(mProcess, SIGNAL(readyReadStandardOutput()), this, SLOT(slotReadProcess())); mProcess->start("cmd /C ping " + param); emit SignalReply(reply_Running, "Running"); } default: emit SignalReply(reply_Error, "Unknown command"); }}
delete mProcess;
(**iterator)->setText(0, "o.o");
C++ (Qt)class CMyIterator : public QTreeWidgetItemIterator {public CMyIterator( ProcessTree * proc, QTreeWidget * tree ); signals: void SignalFinished( void ); // испускается когда обход закончен void SignalError ( void ); // процесс не смог нормально выполнится void SignalNext ( void ); // посылает ProcessTree след команду slots: void SlotReply( int reply, QString txt ); // принимает ответ ProcessTree и переходит на след элемент};
#ifndef TEST_H#define TEST_H#include <QTreeWidgetItemIterator>class QTreeWidget;class ProcessTree;class TreeIterator : public QTreeWidgetItemIterator{ Q_OBJECTpublic: TreeIterator(ProcessTree *proc, QTreeWidget *tree);signals: void signalFinished(); void signalError(); void signalNext();public slots: void slotReply(int reply, QString txt );private: ProcessTree *process; QTreeWidget *tree;};#endif
1>c:\qtsdk\myprojects\myapplication\myapplication\generatedfiles\debug\../../test.h(11) : error C2143: syntax error : missing ';' before 'public'1>c:\qtsdk\myprojects\myapplication\myapplication\generatedfiles\debug\../../test.h(11) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int1>c:\qtsdk\myprojects\myapplication\myapplication\generatedfiles\debug\../../test.h(14) : error C2062: type 'void' unexpected1>c:\qtsdk\myprojects\myapplication\myapplication\generatedfiles\debug\../../test.h(14) : error C2238: unexpected token(s) preceding ';'1>c:\qtsdk\myprojects\myapplication\myapplication\generatedfiles\debug\../../test.h(17) : error C2146: syntax error : missing ':' before identifier 'slots'1>c:\qtsdk\myprojects\myapplication\myapplication\generatedfiles\debug\../../test.h(18) : error C2062: type 'void' unexpected1>c:\qtsdk\myprojects\myapplication\myapplication\generatedfiles\debug\../../test.h(18) : error C2238: unexpected token(s) preceding ';'1>.\GeneratedFiles\Debug\moc_test.cpp(12) : fatal error C1189: #error : "The header file 'test.h' doesn't include <QObject>."
1>.\GeneratedFiles\Debug\moc_test.cpp(51) : error C2039: 'staticMetaObject' : is not a member of 'QTreeWidgetItemIterator'1> c:\qt\4.6.3\include\qtgui\../../src/gui/itemviews/qtreewidgetitemiterator.h(62) : see declaration of 'QTreeWidgetItemIterator'1>.\GeneratedFiles\Debug\moc_test.cpp(61) : error C2227: left of '->metaObject' must point to class/struct/union/generic type1>.\GeneratedFiles\Debug\moc_test.cpp(61) : error C2227: left of '->metaObject' must point to class/struct/union/generic type1>.\GeneratedFiles\Debug\moc_test.cpp(69) : error C2039: 'qt_metacast' : is not a member of 'QTreeWidgetItemIterator'1> c:\qt\4.6.3\include\qtgui\../../src/gui/itemviews/qtreewidgetitemiterator.h(62) : see declaration of 'QTreeWidgetItemIterator'1>.\GeneratedFiles\Debug\moc_test.cpp(74) : error C2039: 'qt_metacall' : is not a member of 'QTreeWidgetItemIterator'1> c:\qt\4.6.3\include\qtgui\../../src/gui/itemviews/qtreewidgetitemiterator.h(62) : see declaration of 'QTreeWidgetItemIterator'1>.\GeneratedFiles\Debug\moc_test.cpp(93) : error C2665: 'QMetaObject::activate' : none of the 4 overloads could convert all the argument types1> c:\qt\4.6.3\include\qtcore\../../src/corelib/kernel/qobjectdefs.h(346): could be 'void QMetaObject::activate(QObject *,int,int,void **)'1> c:\qt\4.6.3\include\qtcore\../../src/corelib/kernel/qobjectdefs.h(347): or 'void QMetaObject::activate(QObject *,const QMetaObject *,int,void **)'1> while trying to match the argument list '(TreeIterator *const , const QMetaObject *, int, int)'1>.\GeneratedFiles\Debug\moc_test.cpp(99) : error C2665: 'QMetaObject::activate' : none of the 4 overloads could convert all the argument types1> c:\qt\4.6.3\include\qtcore\../../src/corelib/kernel/qobjectdefs.h(346): could be 'void QMetaObject::activate(QObject *,int,int,void **)'1> c:\qt\4.6.3\include\qtcore\../../src/corelib/kernel/qobjectdefs.h(347): or 'void QMetaObject::activate(QObject *,const QMetaObject *,int,void **)'1> while trying to match the argument list '(TreeIterator *const , const QMetaObject *, int, int)'1>.\GeneratedFiles\Debug\moc_test.cpp(105) : error C2665: 'QMetaObject::activate' : none of the 4 overloads could convert all the argument types1> c:\qt\4.6.3\include\qtcore\../../src/corelib/kernel/qobjectdefs.h(346): could be 'void QMetaObject::activate(QObject *,int,int,void **)'1> c:\qt\4.6.3\include\qtcore\../../src/corelib/kernel/qobjectdefs.h(347): or 'void QMetaObject::activate(QObject *,const QMetaObject *,int,void **)'1> while trying to match the argument list '(TreeIterator *const , const QMetaObject *, int, int)'
C++ (Qt)class TreeIterator : public QObject{ Q_OBJECTpublic: TreeIterator(ProcessTree *proc, QTreeWidgetIteraor & iter); ...private: ProcessTree * mProcess; QTreeWidgetIterator & mIterator;};