Results 1 to 3 of 3

Thread: Listen to selected network interface chosen on combo box

  1. #1
    Join Date
    May 2014
    Posts
    7
    Qt products
    Qt5
    Platforms
    Windows

    Default Listen to selected network interface chosen on combo box

    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:n_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?

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Listen to selected network interface chosen on combo box

    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

  3. #3
    Join Date
    May 2014
    Posts
    7
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Listen to selected network interface chosen on combo box

    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?

Similar Threads

  1. Network interface, combo box problem
    By davidrhcp in forum Qt Programming
    Replies: 1
    Last Post: 5th May 2014, 16:07
  2. Replies: 1
    Last Post: 23rd April 2011, 09:42
  3. Set selected text in combo box
    By kode in forum Newbie
    Replies: 0
    Last Post: 27th December 2010, 11:06
  4. Stylesheet of selected item in combo-box
    By shrawan0786 in forum Qt Programming
    Replies: 1
    Last Post: 6th December 2010, 10:30
  5. Replies: 12
    Last Post: 22nd March 2009, 11:22

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.