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 <QApplication>
using namespace yremote;
int main(int argc, char *argv[])
{
QApplication a(argc, argv);

View File

@@ -1,14 +1,55 @@
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
#include <qnetwork.h>
#include <QtNetwork/QNetworkReply>
class QNetworkReply;
namespace yremote {
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
manager = new QNetworkAccessManager(this);
}
MainWindow::~MainWindow()
{
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
#include <QMainWindow>
#include "QtNetwork/QNetworkAccessManager"
namespace Ui {
class MainWindow;
}
namespace yremote {
class MainWindow : public QMainWindow
{
Q_OBJECT
@@ -15,8 +18,22 @@ public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
protected:
void func();
private slots:
void on_btn_onoff_clicked();
void on_txt_address_textEdited(const QString &arg1);
private:
Ui::MainWindow *ui;
QString sendCommand(QString cmd);
QString mAddress;
QNetworkAccessManager *manager;
};
}
#endif // MAINWINDOW_H

View File

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

View File

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