C++ (Qt)class Sensor{ Sensor( const QString &name ) : m_name( name ) { } QString name() const { return m_name; } private: QString m_name;}; class PressureSensor : public Sensor{ PressureSensor() : Sensor( trUtf8( "Датчик давления" ) ) {}}; class TempSensor : public Sensor{ TempSensor() : Sensor( trUtf8( "Датчик температуры" ) ) {}};
C++ (Qt)int IcebreakerServer::sensor_01(){ return qrand() % 10 + 10;} int IcebreakerServer::sensor_02(){ return qrand() % 10 + 20;} int IcebreakerServer::sensor_03(){ return qrand() % 10 + 30;} int IcebreakerServer::sensor_04(){ return qrand() % 10 + 40;} int IcebreakerServer::sensor_05(){ return qrand() % 10 + 50;}
C++ (Qt)void MainWindow::readyRead(){ QTcpSocket* clientSocket = (QTcpSocket*)sender(); QDataStream in(clientSocket); in.setVersion(QDataStream::Qt_4_7); for (;;) { if (!m_nextBlockSize) { if (clientSocket->bytesAvailable() < (int)sizeof(quint16)) { break; } in >> m_nextBlockSize; } if (clientSocket->bytesAvailable() < m_nextBlockSize) { break; } QString str; in >> str; QStringList stringList = str.split(','); if (stringList.size() == 5) { ui->sensor01LineEdit->setText(stringList[0]); ui->sensor02LineEdit->setText(stringList[1]); ui->sensor03LineEdit->setText(stringList[2]); ui->sensor04LineEdit->setText(stringList[3]); ui->sensor05LineEdit->setText(stringList[4]); } else { qWarning() << "stringList.size() != 5"; } m_nextBlockSize = 0; }}