it works fine now:
ServerMainWindow
::ServerMainWindow(QWidget* parent,
const char* name
) : MainWindowBase(parent, name),
m_server(0)
{
m_clients.setAutoDelete(true);
proc->addArgument("ipconfig");
proc->addArgument("-all");
QObject::connect(proc,
SIGNAL(readyReadStdout
()),
this,
SLOT(readFromStdout
()));
QObject::connect(m_start,
SIGNAL(clicked
()),
this,
SLOT(slotStartClicked
()));
QObject::connect(m_stop,
SIGNAL(clicked
()),
this,
SLOT(slotStopClicked
()));
proc->start();
}
////////////////////////////////////////////////////////////////////////////////
void ServerMainWindow::readFromStdout(){
// QByteArray data = proc->readStdout();
textEdit1->setText(data);
sendToClients(data);
}
////////////////////////////////////////////////////////////////////////////////
ServerMainWindow::~ServerMainWindow()
{
slotStopClicked();
}
////////////////////////////////////////////////////////////////////////////////
void ServerMainWindow::sendToClients(const QString& text)
{
if (text.isNull()) return;
// iterate over all clients and send them the text
QPtrDictIterator<Client> iter(m_clients);
for (; iter.current() != 0; ++iter)
{
QSocket* sock = iter.current()->socket();
stream << text;
}
}
ServerMainWindow::ServerMainWindow(QWidget* parent, const char* name)
: MainWindowBase(parent, name),
m_server(0)
{
m_clients.setAutoDelete(true);
proc = new QProcess(this);
proc->addArgument("ipconfig");
proc->addArgument("-all");
QObject::connect(proc,SIGNAL(readyReadStdout()),this,SLOT(readFromStdout()));
QObject::connect(m_start, SIGNAL(clicked()), this, SLOT(slotStartClicked()));
QObject::connect(m_stop, SIGNAL(clicked()), this, SLOT(slotStopClicked()));
proc->start();
}
////////////////////////////////////////////////////////////////////////////////
void ServerMainWindow::readFromStdout(){
// QByteArray data = proc->readStdout();
QString data = proc->readStdout();
textEdit1->setText(data);
sendToClients(data);
}
////////////////////////////////////////////////////////////////////////////////
ServerMainWindow::~ServerMainWindow()
{
slotStopClicked();
}
////////////////////////////////////////////////////////////////////////////////
void ServerMainWindow::sendToClients(const QString& text)
{
if (text.isNull()) return;
// iterate over all clients and send them the text
QPtrDictIterator<Client> iter(m_clients);
for (; iter.current() != 0; ++iter)
{
QSocket* sock = iter.current()->socket();
QTextStream stream(sock);
stream << text;
}
}
To copy to clipboard, switch view to plain text mode
but still my client doesn't recive stdout from ipconfig
function sendToClients(data); should send QString to void ServerMainWindow::sendToClients(const QString& text)
is the function sendToClients(const QString& text) correct? or could be there some issue in the client application?
client function that recieves data from server app is:
void ClientMainWindow::slotRead()
{
while (m_socket->canReadLine())
text += m_socket->readLine();
if (!text.isNull())
appendText(text, Output);
}
where
void ClientMainWindow::appendText(const QString& text, Mode mode)
{
switch (mode)
{
case System:
m_textEdit->setColor(Qt::blue);
break;
case Error:
m_textEdit->setColor(Qt::red);
break;
default:
m_textEdit->setColor(Qt::black);
break;
}
m_textEdit->append(text);
}
void ClientMainWindow::slotRead()
{
QString text;
while (m_socket->canReadLine())
text += m_socket->readLine();
if (!text.isNull())
appendText(text, Output);
}
where
void ClientMainWindow::appendText(const QString& text, Mode mode)
{
switch (mode)
{
case System:
m_textEdit->setColor(Qt::blue);
break;
case Error:
m_textEdit->setColor(Qt::red);
break;
default:
m_textEdit->setColor(Qt::black);
break;
}
m_textEdit->append(text);
}
To copy to clipboard, switch view to plain text mode
Bookmarks