QTcpServer listener starts when ran on Windows but not on BeagleBone Black
-
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
#ifndef MAINWINDOW_H
#define MAINWINDOW_H#include <QMainWindow>
#include "serverlistener.h"class ServerListener;
namespace Ui {
class MainWindow;
}class MainWindow : public QMainWindow
{
Q_OBJECTpublic:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();private:
Ui::MainWindow *ui;
ServerListener serverListener;public slots:
void updateStatusMessages(QString line1);};
#endif // MAINWINDOW_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
#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
#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();}
@ -
Hi and welcome to devnet,
Are you using the same Qt version on your computer and on your BBB ? Which is it ?
-
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.
-
Start your application with QT_DEBUG_PLUGINS=1 so you'll see if there's anything funky going on with the plugins loading
-
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
-
Looks like there's no bearer plugin loaded, are they properly installed ?
The QT_DEBUG_PLUGINS is mentioned in the Deploying Plugins chapter