Hi.
I ve got a plugin in which a write some data into the socket:
...
stream << quint32(Data::PluginData) << name << quint32(ProgramViewerMenu::NewImage) << shot.toImage();
screen = shot.toImage();
return array;
...
socket->write(array);
...
array = new QByteArray();
QDataStream stream(array, QIODevice::WriteOnly);
stream.setVersion(QDataStream::Qt_4_2);
QString name = "Program Viewer";
stream << quint32(Data::PluginData) << name << quint32(ProgramViewerMenu::NewImage) << shot.toImage();
screen = shot.toImage();
return array;
...
socket->write(array);
To copy to clipboard, switch view to plain text mode
And in another program I have slot read() which is connected to readyRead() signal of socket.
void Connection::read()
{
DataThread *thread = new DataThread(socket, this);
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()) );
thread->start();
}
void Connection::read()
{
DataThread *thread = new DataThread(socket, this);
connect(thread, SIGNAL(serverData(QByteArray)), this, SLOT(serverData(QByteArray)));
connect(thread, SIGNAL(pluginData(QByteArray)), this, SLOT(pluginData(QByteArray)));
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()) );
thread->start();
}
To copy to clipboard, switch view to plain text mode
DataThread run() function:
void DataThread::run()
{
array = socket->readAll();
quint32 dataType;
streamOut >> dataType;
qDebug() << "data thread dataType" << dataType;
/* QString name;
streamOut >> name;
qDebug() << name;*/
if (dataType == Data::ServerData)
emit serverData(array);
if (dataType == Data::PluginData)
emit pluginData(array);
}
void DataThread::run()
{
QByteArray array;
array = socket->readAll();
QDataStream streamOut(array);
streamOut.setVersion(QDataStream::Qt_4_2);
quint32 dataType;
streamOut >> dataType;
qDebug() << "data thread dataType" << dataType;
/* QString name;
streamOut >> name;
qDebug() << name;*/
if (dataType == Data::ServerData)
emit serverData(array);
if (dataType == Data::PluginData)
emit pluginData(array);
}
To copy to clipboard, switch view to plain text mode
pluginData signal of DataThread is connected to pluginData slot. In this slot I want to read plugin name which was written in plugin function.
{
streamIn >> name;
qDebug() << name;
}
void Connection::pluginData(QByteArray array)
{
QDataStream streamOut(array);
streamOut.setVersion(QDataStream::Qt_4_2);
QString name;
streamIn >> name;
qDebug() << name;
}
To copy to clipboard, switch view to plain text mode
qDebug() << name gives me nothing, null string but I have no idea why. When I tray to read plugin name in thread class before returning array it works. Whats wrong?
Sorry about me english.
Bookmarks