added first network things

This commit is contained in:
2018-04-15 15:43:33 +02:00
parent 13934a8285
commit cfdcd6bb3d
5 changed files with 200 additions and 162 deletions

View File

@@ -1,6 +1,8 @@
#include "mainwindow.h" #include "mainwindow.h"
#include <QApplication> #include <QApplication>
using namespace yremote;
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QApplication a(argc, argv); QApplication a(argc, argv);

View File

@@ -1,14 +1,55 @@
#include "mainwindow.h" #include "mainwindow.h"
#include "ui_mainwindow.h" #include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) : #include <qnetwork.h>
QMainWindow(parent), #include <QtNetwork/QNetworkReply>
ui(new Ui::MainWindow)
class QNetworkReply;
namespace yremote {
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
{ {
ui->setupUi(this); ui->setupUi(this);
manager = new QNetworkAccessManager(this);
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()
{ {
delete ui; delete ui;
} }
void MainWindow::func()
{
QNetworkAccessManager *manager = new QNetworkAccessManager(this);
connect(manager, SIGNAL(finished(QNetworkReply*)),
this, SLOT(replyFinished(QNetworkReply*)));
manager->get(QNetworkRequest(QUrl("http://qt-project.org")));
}
void MainWindow::on_btn_onoff_clicked()
{
qDebug() << "void MainWindow::on_btn_onoff_clicked()";
sendCommand("<YAMAHA_AV cmd=\"GET\"><Main_Zone><Input><Input_Sel>GetParam</Input_Sel></Input></Main_Zone></YAMAHA_AV>");
}
QString MainWindow::sendCommand(QString cmd)
{
QString res;
QNetworkRequest request;
request.setUrl("http://" + mAddress + ":80/YamahaRemoteControl/ctrl");
QNetworkReply *reply = manager->get(request);
qDebug() << reply->readAll();
return res;
}
}
void yremote::MainWindow::on_txt_address_textEdited(const QString &arg1)
{
mAddress = arg1;
}

View File

@@ -2,11 +2,14 @@
#define MAINWINDOW_H #define MAINWINDOW_H
#include <QMainWindow> #include <QMainWindow>
#include "QtNetwork/QNetworkAccessManager"
namespace Ui { namespace Ui {
class MainWindow; class MainWindow;
} }
namespace yremote {
class MainWindow : public QMainWindow class MainWindow : public QMainWindow
{ {
Q_OBJECT Q_OBJECT
@@ -15,8 +18,22 @@ public:
explicit MainWindow(QWidget *parent = 0); explicit MainWindow(QWidget *parent = 0);
~MainWindow(); ~MainWindow();
protected:
void func();
private slots:
void on_btn_onoff_clicked();
void on_txt_address_textEdited(const QString &arg1);
private: private:
Ui::MainWindow *ui; Ui::MainWindow *ui;
QString sendCommand(QString cmd);
QString mAddress;
QNetworkAccessManager *manager;
}; };
}
#endif // MAINWINDOW_H #endif // MAINWINDOW_H

View File

@@ -14,164 +14,142 @@
<string>yremote</string> <string>yremote</string>
</property> </property>
<widget class="QWidget" name="centralWidget"> <widget class="QWidget" name="centralWidget">
<widget class="QDial" name="dial"> <layout class="QGridLayout" name="gridLayout">
<property name="geometry"> <item row="0" column="0">
<rect> <widget class="QPushButton" name="btn_onoff">
<x>370</x> <property name="text">
<y>10</y> <string>On</string>
<width>121</width> </property>
<height>121</height> </widget>
</rect> </item>
</property> <item row="0" column="1">
</widget> <widget class="QLabel" name="label">
<widget class="QLineEdit" name="txt_address"> <property name="text">
<property name="geometry"> <string>Address:</string>
<rect> </property>
<x>170</x> </widget>
<y>10</y> </item>
<width>181</width> <item row="0" column="2">
<height>21</height> <widget class="QLineEdit" name="txt_address">
</rect> <property name="text">
</property> <string>10.0.0.5</string>
<property name="text"> </property>
<string>10.0.0.5</string> <property name="alignment">
</property> <set>Qt::AlignCenter</set>
<property name="alignment"> </property>
<set>Qt::AlignCenter</set> </widget>
</property> </item>
</widget> <item row="0" column="3" rowspan="2">
<widget class="QLabel" name="lbl_volume"> <widget class="QDial" name="dial"/>
<property name="geometry"> </item>
<rect> <item row="1" column="0" rowspan="2" colspan="3">
<x>370</x> <widget class="QGroupBox" name="groupBox">
<y>130</y> <property name="title">
<width>121</width> <string>Input</string>
<height>31</height> </property>
</rect> <widget class="QPushButton" name="btn_hdmi1">
</property> <property name="geometry">
<property name="font"> <rect>
<font> <x>10</x>
<family>Source Code Pro Medium</family> <y>30</y>
<pointsize>16</pointsize> <width>80</width>
</font> <height>21</height>
</property> </rect>
<property name="frameShape"> </property>
<enum>QFrame::StyledPanel</enum> <property name="text">
</property> <string>HDMI 1</string>
<property name="frameShadow"> </property>
<enum>QFrame::Sunken</enum> </widget>
</property> <widget class="QPushButton" name="btn_hdmi2">
<property name="text"> <property name="geometry">
<string>-66.5</string> <rect>
</property> <x>10</x>
<property name="alignment"> <y>60</y>
<set>Qt::AlignCenter</set> <width>80</width>
</property> <height>21</height>
</widget> </rect>
<widget class="QLabel" name="label"> </property>
<property name="geometry"> <property name="text">
<rect> <string>HDMI 2</string>
<x>120</x> </property>
<y>10</y> </widget>
<width>51</width> <widget class="QPushButton" name="btn_hdmi3">
<height>21</height> <property name="geometry">
</rect> <rect>
</property> <x>10</x>
<property name="text"> <y>90</y>
<string>Address:</string> <width>80</width>
</property> <height>21</height>
</widget> </rect>
<widget class="QGroupBox" name="groupBox"> </property>
<property name="geometry"> <property name="text">
<rect> <string>HDMI 3</string>
<x>10</x> </property>
<y>40</y> </widget>
<width>201</width> <widget class="QPushButton" name="btn_spotify">
<height>121</height> <property name="geometry">
</rect> <rect>
</property> <x>110</x>
<property name="title"> <y>30</y>
<string>Input</string> <width>80</width>
</property> <height>21</height>
<widget class="QPushButton" name="btn_hdmi1"> </rect>
<property name="geometry"> </property>
<rect> <property name="text">
<x>10</x> <string>Spotify</string>
<y>30</y> </property>
<width>80</width> </widget>
<height>21</height> <widget class="QPushButton" name="btn_airplay">
</rect> <property name="geometry">
</property> <rect>
<property name="text"> <x>110</x>
<string>HDMI 1</string> <y>60</y>
</property> <width>80</width>
</widget> <height>21</height>
<widget class="QPushButton" name="btn_hdmi2"> </rect>
<property name="geometry"> </property>
<rect> <property name="text">
<x>10</x> <string>Airplay</string>
<y>60</y> </property>
<width>80</width> </widget>
<height>21</height> <widget class="QPushButton" name="btn_audioin">
</rect> <property name="geometry">
</property> <rect>
<property name="text"> <x>110</x>
<string>HDMI 2</string> <y>90</y>
</property> <width>80</width>
</widget> <height>21</height>
<widget class="QPushButton" name="btn_hdmi3"> </rect>
<property name="geometry"> </property>
<rect> <property name="text">
<x>10</x> <string>Audio In</string>
<y>90</y> </property>
<width>80</width> </widget>
<height>21</height> </widget>
</rect> </item>
</property> <item row="2" column="3">
<property name="text"> <widget class="QLabel" name="lbl_volume">
<string>HDMI 3</string> <property name="font">
</property> <font>
</widget> <family>Source Code Pro Medium</family>
<widget class="QPushButton" name="btn_spotify"> <pointsize>16</pointsize>
<property name="geometry"> </font>
<rect> </property>
<x>110</x> <property name="frameShape">
<y>30</y> <enum>QFrame::StyledPanel</enum>
<width>80</width> </property>
<height>21</height> <property name="frameShadow">
</rect> <enum>QFrame::Sunken</enum>
</property> </property>
<property name="text"> <property name="text">
<string>Spotify</string> <string>-66.5</string>
</property> </property>
</widget> <property name="alignment">
<widget class="QPushButton" name="btn_airplay"> <set>Qt::AlignCenter</set>
<property name="geometry"> </property>
<rect> </widget>
<x>110</x> </item>
<y>60</y> </layout>
<width>80</width>
<height>21</height>
</rect>
</property>
<property name="text">
<string>Airplay</string>
</property>
</widget>
</widget>
<widget class="QPushButton" name="btn_onoff">
<property name="geometry">
<rect>
<x>20</x>
<y>10</y>
<width>80</width>
<height>21</height>
</rect>
</property>
<property name="text">
<string>On</string>
</property>
</widget>
</widget> </widget>
</widget> </widget>
<layoutdefault spacing="6" margin="11"/> <layoutdefault spacing="6" margin="11"/>

View File

@@ -4,7 +4,7 @@
# #
#------------------------------------------------- #-------------------------------------------------
QT += core gui QT += core gui network
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets greaterThan(QT_MAJOR_VERSION, 4): QT += widgets