-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainwindow.cpp
102 lines (88 loc) · 2.62 KB
/
mainwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include <QDateTime>
#include <QListWidget>
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <vector>
using namespace std;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
socket = new QTcpSocket(this);
}
QString ip;
// Realiza a desconeção
void MainWindow::disconnect(){
socket->disconnectFromHost();
qDebug() << "Disconect from IP";
}
void MainWindow::listarIps(){
QString str1;
QByteArray array;
QStringList list;
QDateTime datetime;
QListWidget* lista = new QListWidget();
QString str;
str1 = socket->write("list /r/n");
socket->waitForBytesWritten();
socket->waitForReadyRead();
qDebug() << socket->bytesAvailable();
while(socket->bytesAvailable()){
str = socket->readLine().replace("\n","").replace("\r","");
ui->listWidget->addItem(str);
}
}
MainWindow::~MainWindow(){
delete ui;
delete socket;
}
void MainWindow::tcpConnect(){
// Guarda o valor do IP
ip = ui->lineIp->text();
socket->connectToHost(ip,1234);
if(socket->waitForConnected(3000)){
qDebug()<< "Connected";
}
else{
qDebug() << "Disconnected";
}
}
void MainWindow::mostraTempo(int value){
// Muda o valor do slider
int i = value;
QString s = QString::number(i);
ui->labelTime->setText(s);
}
void MainWindow::getData(){
QString str;
QByteArray array;
QStringList list;
QDateTime datetime;
qDebug() << "to get data...";
qDebug() << socket->state();
if(socket->state() == QAbstractSocket::ConnectedState){
if(socket->isOpen()){
qDebug() << "reading...";
str = "get "+ ip + "\r\n";
socket->write(str.toUtf8());
socket->waitForBytesWritten();
socket->waitForReadyRead();
qDebug() << socket->bytesAvailable();
std::vector<int> data;
std::vector<int>:: iterator it = data.begin();
std::vector<int>:: iterator itend = data.end();
while(socket->bytesAvailable()){
str = socket->readLine().replace("\n","").replace("\r","");
list = str.split(" ");
if(list.size() == 2){
datetime.fromString(list.at(0),Qt::ISODate);
str = list.at(1);
qDebug() << datetime << ": " << str;
data.push_back(str.toInt());
// ui->widgetPlotter(str);
}
}
}
}
}