felo188
22nd August 2011, 13:20
Hi,
I wolud like to connect via ethernet with microcontroller. At the beginning i try with an example broadcast receiver and only think i change was
QHostAddress address;
address.setAddress(QString("192.168.20.1"));
udpSocket->bind(address, QUdpSocket::ShareAddress);
Next i try use telnet (hyperterminal) to connect and send some data. I sets the same address like in qt, connect using: TCP/IP (Winsock) and port number 23. But the hyperterminal shows message window with Unable to connect.
And my first question is how to send some data (binary or string) from application like hyperterminal (maybe other) to gui in qt using ethernet (QNetwork). Maybe is some software allows me to put some data to chosen address.
Secondly i try to write my code but now using tcp/ip socket, not udp.
void MainWindow::receivData()
{
if (receivSocket->waitForConnected(3000))
{
qDebug() << "Connected";
}
QByteArray buffer = receivSocket->read();
bool ok;
int data = buffer.toInt(&ok,10);
ui->label->setText(QString::number(data));
}
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
receivSocket = new QTcpSocket(this);
connect(receivSocket,SIGNAL(readyRead()),this,SLOT (receivData()));
QHostAddress address;
address.setAddress(QString("192.168.20.1"));
receivSocket->connectToHost(address,QIODevice::ReadOnly);
}
and in .h
#include <QtNetwork/QTcpSocket>
...
private:
QTcpSocket *receivSocket;
private slots:
void receivData();
I try to compile it but are some errors. error: no matching function for call to 'QTcpSocket::read()' Follow http://doc.qt.nokia.com/latest/network-programming.html (this) QTcpSocket contains read(). My second question is what i should add/change in code if i want to receive some data.
Thanks in advance for any help.
I wolud like to connect via ethernet with microcontroller. At the beginning i try with an example broadcast receiver and only think i change was
QHostAddress address;
address.setAddress(QString("192.168.20.1"));
udpSocket->bind(address, QUdpSocket::ShareAddress);
Next i try use telnet (hyperterminal) to connect and send some data. I sets the same address like in qt, connect using: TCP/IP (Winsock) and port number 23. But the hyperterminal shows message window with Unable to connect.
And my first question is how to send some data (binary or string) from application like hyperterminal (maybe other) to gui in qt using ethernet (QNetwork). Maybe is some software allows me to put some data to chosen address.
Secondly i try to write my code but now using tcp/ip socket, not udp.
void MainWindow::receivData()
{
if (receivSocket->waitForConnected(3000))
{
qDebug() << "Connected";
}
QByteArray buffer = receivSocket->read();
bool ok;
int data = buffer.toInt(&ok,10);
ui->label->setText(QString::number(data));
}
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
receivSocket = new QTcpSocket(this);
connect(receivSocket,SIGNAL(readyRead()),this,SLOT (receivData()));
QHostAddress address;
address.setAddress(QString("192.168.20.1"));
receivSocket->connectToHost(address,QIODevice::ReadOnly);
}
and in .h
#include <QtNetwork/QTcpSocket>
...
private:
QTcpSocket *receivSocket;
private slots:
void receivData();
I try to compile it but are some errors. error: no matching function for call to 'QTcpSocket::read()' Follow http://doc.qt.nokia.com/latest/network-programming.html (this) QTcpSocket contains read(). My second question is what i should add/change in code if i want to receive some data.
Thanks in advance for any help.