blob: 80a76580c82e3531bf1d698200347b05c5efff17 (
plain)
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
|
#include <QSqlDatabase>
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "main.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
// db = QSqlDatabase::addDatabase("QMYSQL");
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
dbRef.close();
delete ui;
}
void MainWindow::on_actionAbout_triggered()
{
QMessageBox::warning(this, "Oops..", "Task Failed succesfully ;)");
}
void MainWindow::on_pushButton_clicked()
{
// dbRef = QSqlDatabase::addDatabase("QMYSQL");
// dbRef.setHostName("localhost");
// dbRef.setUserName("root");
// dbRef.setPassword("Ab12345!");
// dbRef.setDatabaseName("thecrapbox");
series = new QLineSeries();
QChart *chart = new QChart();
if(dbRef.open()){
QMessageBox::information(this, "Connection", "GREAT SUCCES!");
QSqlQuery queryGraphData;
queryGraphData.exec("SELECT id, temp FROM tblMain LIMIT 16 ORDER BY desc;");
// ui->tableView->setModel(pQueryModel);
for (int i = 0; queryGraphData.next(); ++i) {
series->append(queryGraphData.value(0).toInt(), queryGraphData.value(1).toInt());
}
chart->legend()->show();
chart->addSeries(series);
chart->createDefaultAxes();
chart->setTitle("Hellow!");
chartView = new QChartView(chart);
MainWindow::setCentralWidget(chartView);
} else {
QMessageBox::warning(this, "No connection", "Failed to connect");
}
}
void MainWindow::on_actionConnection_triggered()
{
_dbConenctor = new dbConnector(this);
_dbConenctor->show();
}
|