Connecting interface to socket



  • I have combobox with a list of interfaces. when interface is chosen a table widget (called packet) should display the packet information.

    i have been playing with the sockets and QNetworkInterface functions, i was wandering whether or not that what i have if right? i have left some comments where im unsure about a couple of things.

    monice.h

    @
    private slots:

       void on_actionExit_triggered();
    
       void on_comboBox_Interface_activated(const QString &arg1);
    

    @

    socket.h

    @
    #ifndef SOCKET_H
    #define SOCKET_H

    #include <QObject>
    #include <QTcpSocket>
    #include <QAbstractSocket>
    #include <QTcpServer>

    namespace ui{
    class Socket;
    }
    namespace packet {
    class Socket;

    }
    class Socket : public QObject
    {
    Q_OBJECT
    public:

    explicit Socket(QObject *parent = 0);
    void Test();
    void packet();
    

    signals:

    void connected();
    void disconnected();
    void bytesWritten ( qint64 bytes );
    void readyRead();
    void listen();
    

    public slots:

    void on_comboBox_Interface_activated(const QString &arg1);
    

    private:
    QAbstractSocket *socket;

    };

    #endif // SOCKET_H
    @

    main.cpp

    @
    #include "monice.h"
    #include <QApplication>
    #include <QMainWindow>
    #include <QString>
    #include <QObject>
    #include <QApplication>
    #include <cstdlib>
    #include <QDebug>
    #include <QDir>
    #include <QFileInfo>
    #include <QFile>
    #include <QString>
    #include <QIODevice>
    #include <QtGui>
    #include <QTcpServer>
    #include <QTextStream>
    #include <socket.h>

    QString mFile = ("C:/Monice/BW/MBW.txt");

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    Monice w;
    w.show();

     Socket mTest;
     mTest.Test();
    
    QTextStream pText;
    pText.readLine();
    
    
    // creating directory upon run for user input
    QDir mDir;
    mDir.mkpath("C:/Monice/BW");
    
    return a.exec&#40;&#41;;
    

    }
    @

    monice.cpp

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

    {
    QTcpSocket<on_comboBox_Interface_activated> connect = QNetworkInterface::addressEntries();//this is complete garble any pointers in the right direction would be apprciated
    ui->packet->row(1,1(WriteOnly))// trying to write the packet data to the table, would i need to directly link socket in this line?

    }
    @

    socket.cpp

    @
    #include "socket.h"
    #include "QObject"
    #include "QtCore"
    #include "QNetworkConfigurationManager"
    #include "QNetworkInterface"
    #include "QHostAddress"
    #include "QString"
    #include "QFile"
    #include "QLineEdit"
    #include "QDir"
    #include "QApplication"
    #include "QMainWindow"
    #include "QTcpSocket"
    #include "QTcpServer"
    #include "monice.h"
    #include "ui_monice.h"

    Socket::Socket(QObject *parent) :
    QObject(parent)
    {
    socket = new QAbstractSocket(this);

    connect(socket->SINGAL(connected)), this, SLOT(on_comboBox_Interface_activated(QString));

    }

    void QNetworkInterface::addressEntries()
    {
    // Would i put mulitple sockets in here to connect the ip addresses?
    }

    //<- every below here is from a tutorial online which i tried to implement
    //<- after looking at the QAbstractSocket in the documentation,
    //<- I Wasn't sure if it really accomplish what im trying to attempt

    // a test function to see if connection can be made to the TcpSocket
    void Socket::Test()
    {
    //connects the socket to the connected slot
    connect(socket,SIGNAL(connected()), this, SLOT(connected()));
    //connects the socket to the disconnected slot
    connect(socket,SIGNAL(disconnected()), this, SLOT(disconnected()));
    //connects the socket to the readyRead slot
    connect(socket,SIGNAL(readyRead()), this, SLOT(readyRead()));
    //connects the socket to the BytesWritten Slot
    connect(socket,SIGNAL(bytesWritten(qint64)), this, SLOT(bytesWritten(qint64)));

    socket->connect(QNetworkInterface::addressEntries());
    

    }

    void Socket::connected()
    {

    }

    void Socket::disconnected()
    {

    }

    void Socket::bytesWritten ( qint64 bytes )
    {

    }

    void Socket::readyRead()
    {

    //use QTextStream here to write signals to table?

    }

    void Socket:: listen()
    {

    }
    @

    i cut a couple short on the account that the rest of the code was irrelevant to the issue.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.