Puneet2793
15th May 2017, 10:55
Hi I have two different classes A and B files. I am trying to access the object of class A from B. The function gets called i can see via the Debug messages but It doesn't set the textbrowser with the string I passed. Here is the code for Main window
Here is the code for main.cpp
#include <QApplication>
#include "window.h"
#include "bbbserver.h"
int main(int argc, char **argv)
{
QApplication app (argc, argv);
bbbServer server;
Window window;
window.setStyleSheet("background-color: rgb(226, 226, 226);");
window.showFullScreen();
return app.exec();
}
Here is the code for window.h
#ifndef WINDOW_H
#define WINDOW_H
#include <QWidget>
class QPushButton;
class QTextBrowser;
class QProcess;
class QFile;
class Window : public QWidget
{
Q_OBJECT
public:
explicit Window(QWidget *parent = 0);
void setStatusWindow(QString str);
QTextBrowser *statusWindow;
private slots:
};
Here is window.cpp
#include "window.h"
#include <QPushButton>
#include <QProcess>
#include <QTextBrowser>
#include <QDebug>
Window::Window(QWidget *parent) : QWidget(parent)
{
// Create and position the buttons on the main window
/*************** text browser *********************/
statusWindow = new QTextBrowser(this);
statusWindow->setMinimumSize(QSize(0,0));
statusWindow->setMaximumSize(QSize(10000,10000));
statusWindow->setGeometry(175, 50, 440, 420);
statusWindow->setStyleSheet("background-color: rgb(236, 236, 236);");
}
void Window::setStatusWindow(QString str)
{
qDebug() << "Hit in Setter function to set Text";
statusWindow->setText(str);
}
and here is the bbbserver.cpp
#include "bbbserver.h"
#include "window.h"
bbbServer::bbbServer(QObject *parent):
QObject(parent)
{
/*************************** SERVER *********************************/
server = new QTcpServer(this);
connect(server, SIGNAL(newConnection()), this, SLOT(newConnection()));
if(!server->listen(QHostAddress::QHostAddress("192.168.0.1"), 5000))
{
qDebug() << "SERVER NOT STARTED";
}
else
{
qDebug() << "SERVER STARTED";
}
}
void bbbServer::newConnection()
{
QTcpSocket *socket= server->nextPendingConnection();
socket->write("Connection from 192.168.0.1 BBB\n");
socket->flush();
socket->waitForBytesWritten(30000);
socket->waitForReadyRead(30000);
qDebug() << (clientMsg = socket->readAll());
// creating an instance of window to change Euid text Browser
Window window;
window.setStatusWindow("clientMsg");
}
The problem here is whenever I send a message from the client side. I get the string and debug messages that code is hitting in setter function but I doesn't set the value of Status Window. Whats wrong there?
Here is the code for main.cpp
#include <QApplication>
#include "window.h"
#include "bbbserver.h"
int main(int argc, char **argv)
{
QApplication app (argc, argv);
bbbServer server;
Window window;
window.setStyleSheet("background-color: rgb(226, 226, 226);");
window.showFullScreen();
return app.exec();
}
Here is the code for window.h
#ifndef WINDOW_H
#define WINDOW_H
#include <QWidget>
class QPushButton;
class QTextBrowser;
class QProcess;
class QFile;
class Window : public QWidget
{
Q_OBJECT
public:
explicit Window(QWidget *parent = 0);
void setStatusWindow(QString str);
QTextBrowser *statusWindow;
private slots:
};
Here is window.cpp
#include "window.h"
#include <QPushButton>
#include <QProcess>
#include <QTextBrowser>
#include <QDebug>
Window::Window(QWidget *parent) : QWidget(parent)
{
// Create and position the buttons on the main window
/*************** text browser *********************/
statusWindow = new QTextBrowser(this);
statusWindow->setMinimumSize(QSize(0,0));
statusWindow->setMaximumSize(QSize(10000,10000));
statusWindow->setGeometry(175, 50, 440, 420);
statusWindow->setStyleSheet("background-color: rgb(236, 236, 236);");
}
void Window::setStatusWindow(QString str)
{
qDebug() << "Hit in Setter function to set Text";
statusWindow->setText(str);
}
and here is the bbbserver.cpp
#include "bbbserver.h"
#include "window.h"
bbbServer::bbbServer(QObject *parent):
QObject(parent)
{
/*************************** SERVER *********************************/
server = new QTcpServer(this);
connect(server, SIGNAL(newConnection()), this, SLOT(newConnection()));
if(!server->listen(QHostAddress::QHostAddress("192.168.0.1"), 5000))
{
qDebug() << "SERVER NOT STARTED";
}
else
{
qDebug() << "SERVER STARTED";
}
}
void bbbServer::newConnection()
{
QTcpSocket *socket= server->nextPendingConnection();
socket->write("Connection from 192.168.0.1 BBB\n");
socket->flush();
socket->waitForBytesWritten(30000);
socket->waitForReadyRead(30000);
qDebug() << (clientMsg = socket->readAll());
// creating an instance of window to change Euid text Browser
Window window;
window.setStatusWindow("clientMsg");
}
The problem here is whenever I send a message from the client side. I get the string and debug messages that code is hitting in setter function but I doesn't set the value of Status Window. Whats wrong there?