C++ (Qt)QString path = QDir::currentPath()+QString("/database.sqlite");
C++ (Qt)#ifndef SENSOR_H#define SENSOR_H #include <QString> class Sensor{public: Sensor(const QString &sensorName, const QString &portName); QString sensorName() const { return mSensorName; } QString portName() const { return mPortName; } int value() const; int id() const { return mID; } private: QString mSensorName; QString mPortName; static int mID;}; #endif // SENSOR_H
C++ (Qt)#include "Sensor.h" #include <QTime> Sensor::Sensor(const QString &sensorName, const QString &portName) : mSensorName(sensorName), mPortName(portName){ qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); mID++;} int Sensor::value () const{ return qrand() % 10 + (mID * 10);}
C++ (Qt)int Sensor::mID = 0;
C++ (Qt)#ifndef SENSOR_H#define SENSOR_H #include <QString> class Sensor{public: Sensor(const QString &sensorName, const QString &portName); QString sensorName() const { return mSensorName; } QString portName() const { return mPortName; } int value() const; int id() const { return mID; } private: QString mSensorName; QString mPortName; int mID; static int mSeq;}; #endif // SENSOR_H
C++ (Qt)#include "Sensor.h" #include <QTime> int Sensor::mSeq = 0; Sensor::Sensor(const QString &sensorName, const QString &portName) : mSensorName(sensorName), mPortName(portName), mID( mSeq++ ){ qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));} int Sensor::value () const{ return qrand() % 10 + (mID * 10);}
C++ (Qt)int Sensor::value () const{ return qrand() % 10 + (mID * 10);}
C++ (Qt)class Foo {public: static int generateId() { static int id = 0; return id++; }}
C++ (Qt)void IcebreakerServer::sendToViewer(QTcpSocket *socket, const QString &str){ QByteArray arrBlock; QDataStream out(&arrBlock, QIODevice::WriteOnly); out.setVersion(QDataStream::Qt_4_7); out << quint16(0) << str; out.device()->seek(0); out << quint16(arrBlock.size() - sizeof(quint16)); socket->write(arrBlock);}
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 inputData; in >> inputData; QStringList sensorsList = inputData.split(';'); qDebug() << inputData; if ((sensorsList.size() == 3) && (sensorsList[0] == QString("alailableRange"))) { QDateTime time; // Begin of Range time.setMSecsSinceEpoch(sensorsList[1].toULongLong()); ui->beginPossibleLineEdit->setText(time.toString()); // End of Range time.setMSecsSinceEpoch(sensorsList[2].toULongLong()); ui->endPossibleLineEdit->setText(time.toString()); } else { qDebug() << "to table"; if (sensorsList.size() != mModel->rowCount()) { mRows = sensorsList.size(); delete mModel; mModel = new QStandardItemModel(mRows, mColumns, this); setHeaderData(); ui->currentTable->setModel(mModel); } for (int i = 0; i < sensorsList.size(); ++i) { QStringList list = sensorsList[i].split(','); if (list.size() == mModel->columnCount()) { QModelIndex index; // Set data to the table for (int j = 0; j < list.size(); ++j) { index = mModel->index(i, j); mModel->setData(index, list[j]); } } } } m_nextBlockSize = 0; }}