PDA

View Full Version : Listen to selected network interface chosen on combo box



davidrhcp
8th May 2014, 00:52
i got this code that is suppose to - when a network interface is chosen from the 'comboBox_Interface' widget listen to packets and write to 'packet' widget.

I have tried using similar code patterns from the same project and have come up with:

@
void Monice::on_comboBox_Interface_activated(const QString &arg1)
{

QTextStream pText;
pText.read(ui->comboBox_Interface)

if (pText.setDevice(QNetworkInterface::flags())
{
QTextStream out(server);
out << ui->packet->text();
}
}
@

its very temperamental, im confused as to whether or not i should be using Qtextstream first to read the combobox (which im pretty sure i should) but if thats the case how do i get the program to understand that its an interface i won't it to listen to?
i know i can use QTcpScocket and server, not to sure which is the one to use for listening and writing packets?

ChrisW67
8th May 2014, 01:44
I would be surprised if that code compiled, let alone work. For example, QTextStream::read() takes an int argument and you are giving it a QComboBox*, and QNetworkInterface::flags() is not a static function.

The QString arg1 contains, presumably, the name of an interface. You need to use that to obtain a QNetworkInterface object (QNetworkInterface::interfaceFromName()), then open a socket (TCP or UDP?) to connect and/or listen on a port at one of the IP addresses corresponding to that interface (QNetworkInterface::addressEntries()). The socket object needs to be connected to suitable slots to handle new connections (if applicable), received data, and errors etc. In the slot handling incoming data you need to deal with assembling messages before you can consider how to get them into the "packet" widget (whatever that is). QTextStream may be of some use once you have a complete message received and ready to process; it is of no use in dealing with the combo box.

You really need to start with a statement of the requirements and have a look at Network Programming

davidrhcp
8th May 2014, 12:46
would using a server based class be better since it has more appropiate functions for listening to alladdresses? would i need to create a Qtcp/Udp socket for every address? and then create a seperate socket to write to each row of my table?