Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. QTcpServer listener starts when ran on Windows but not on BeagleBone Black
QtWS25 Last Chance

QTcpServer listener starts when ran on Windows but not on BeagleBone Black

Scheduled Pinned Locked Moved Mobile and Embedded
6 Posts 2 Posters 1.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    gwhitney19
    wrote on last edited by
    #1

    I'm new to Qt and was wondering if anyone could help me out with the following code. It compiles and runs as expected in Windows, but when I compile and run it on my BeagleBone Black either the listener never starts or the listener doesn't stay up long enough for me to connect. Is there some library I'm using that doesn't work properly on embedded devices? Any help would be greatly appreciated.

    mainwindow.h

    @
    //mainwindow.h

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H

    #include <QMainWindow>
    #include "serverlistener.h"

    class ServerListener;
    namespace Ui {
    class MainWindow;
    }

    class MainWindow : public QMainWindow
    {
    Q_OBJECT

    public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

    private:
    Ui::MainWindow *ui;
    ServerListener serverListener;

    public slots:
    void updateStatusMessages(QString line1);

    };

    #endif // MAINWINDOW_H
    @

    serverlistener.h

    @
    //serverlistener.h

    #ifndef SERVERLISTENER_H
    #define SERVERLISTENER_H

    #include <QtNetwork/QTcpServer>
    #include <QObject>

    class ServerListener : public QTcpServer
    {
    Q_OBJECT;
    public:
    explicit ServerListener(QObject *parent = 0);
    ~ServerListener();

    protected:
    void incomingConnection(int descriptor);

    signals:
    void statusMessage(QString line1);

    public slots:
    void readClient();
    void discardClient();

    };

    #endif // SERVERLISTENER_H
    @

    mainwindow.cpp

    @
    //mainwindow.cpp

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include "serverlistener.h"

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);

    connect(&serverListener, SIGNAL(statusMessage(QString)), this, SLOT(updateStatusMessages(QString)));
    
    if (!serverListener.listen(QHostAddress::LocalHost, 1234)) {
        qCritical("Error opening port 1234.");
        serverListener.close();
        return;
    }
    //ui->textEdit->insertPlainText("This is a test\n Line2");
    

    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }

    void MainWindow::updateStatusMessages(QString line1)
    {
    //qDebug() << "Called updatedStatusMessage";
    ui->textEdit->insertPlainText(line1);

    }
    @

    serverlistener.cpp

    @
    //serverlistener.cpp

    #include "serverlistener.h"
    #include <QTcpSocket>
    #include <iostream>

    using namespace std;

    ServerListener::ServerListener(QObject *parent) :
    QTcpServer(parent)
    {
    // serverSocket = new QTcpServer(this);

    cout << "Listening" << endl;
    

    }

    ServerListener::~ServerListener() {
    cout << "Destruction" << endl;
    //serverSocket->close();
    }

    void ServerListener::incomingConnection(int descriptor) {

    cout << "Incoming connection" << endl;
    emit statusMessage("Incoming Connection");
    //ServerThread *thread = new ServerThread(descriptor, this);
    
    QTcpSocket *s = new QTcpSocket(this);
    connect(s, SIGNAL(readyRead()), this, SLOT(readClient()));
    connect(s, SIGNAL(disconnected()), this, SLOT(discardClient()));
    s->setSocketDescriptor(descriptor);
    

    }

    void ServerListener::readClient()
    {
    QTcpSocket socket = (QTcpSocket)sender();
    if(socket->canReadLine()){
    QString url = QString(socket->readLine());

       emit statusMessage("\n"+ url);
    
    
    
       QTextStream res(socket);
       res.setAutoDetectUnicode(true);
       res << "HTTP/1.0 200 Ok\r\n";
    
       socket->close();
    
    
    
       if (socket->state() == QTcpSocket::UnconnectedState){
           delete socket;
       }
    
    }
    

    }

    void ServerListener::discardClient()
    {
    QTcpSocket socket = (QTcpSocket)sender();
    socket->deleteLater();

    }
    @

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Are you using the same Qt version on your computer and on your BBB ? Which is it ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • G Offline
        G Offline
        gwhitney19
        wrote on last edited by
        #3

        Hello thanks for your help.

        I'm using 5.2.1 on both. On the BeagleBone Black I'm lunching my app with the "-platform linuxfb" parameter. Do I also need the "-plug" parameter along with a network plugin? I'm use to using -qws from 4.8.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Start your application with QT_DEBUG_PLUGINS=1 so you'll see if there's anything funky going on with the plugins loading

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • G Offline
            G Offline
            gwhitney19
            wrote on last edited by
            #5

            Below is a link to the output(since it was to large to post) of what I'm getting when I run my app with the DEBUG turned on. No error jumps out to me as an issue that would cause a problem with the network listener. If anyone could take a quick look to make sure I'm not missing anything that would be great.

            Where can I find any documentation on the configuration parameter for 5.2.1, like the QT_DEBUG_PLUGINS environment variable and the "-platform" command line parameter?

            Thanks,
            Greg

            "Debug Output":https://drive.google.com/folderview?id=0B4qEXFuohZf6Y2lXVzV0UWdQeWc&usp=sharing

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Looks like there's no bearer plugin loaded, are they properly installed ?

              The QT_DEBUG_PLUGINS is mentioned in the Deploying Plugins chapter

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved