C++ (Qt)int main(int argc, char *argv[]){ QCoreApplication app( argc, argv ); VFServer server; QObject::connect( &server, SIGNAL( finished() ), &app, SLOT( quit() ) ); // Когда объект server пошлет сигнал finished, завершить eventloop return app.exec();}
C++ (Qt)QFile file;file.open( stdio, QIODevice::ReadOnly );connect( &file, SIGNAL( readyRead() ), SLOT( readUserCommand() );
<Сие конструктор> file.open(stdin, QIODevice::ReadOnly); connect(&file, SIGNAL(readyRead()), this, SLOT(getCommand()));<>void VFServer::getCommand(){ QTextStream stre(&file); QString serverCommand; serverCommand = stre.readLine(); QString command = serverCommand.toUpper(); if (command == "EXIT") { emit finished(); return; } runCommand(command);}
C++ (Qt)#include <QCoreApplication>#include <QFile>#include <QSocketNotifier>#include <QDebug> class StdinReader : public QObject{ Q_OBJECTpublic: StdinReader(); public slots: void readCommand(); private: QFile m_stdin; QSocketNotifier *m_notifier;}; StdinReader::StdinReader(){ if( !m_stdin.open( stdin, QIODevice::ReadOnly ) ) { qDebug() << "Error attach stdin"; return; } m_notifier = new QSocketNotifier( m_stdin.handle(), QSocketNotifier::Read, this ); connect( m_notifier, SIGNAL( activated( int ) ), SLOT( readCommand() ) );} void StdinReader::readCommand(){ QByteArray str = m_stdin.readLine(); qDebug() << "Data:" << str; } int main( int argc, char *argv[] ){ QCoreApplication app( argc, argv ); StdinReader reader; return app.exec();} #include "main.moc"