I was building a bluetooth controlled display using Qt and raspberrypi.The raspberrypi will have a bluetooth service running on it and when I connect to the BluetoothServer. The user can choose to either a display a message or upload and display an image. I use QBluetoothSocket to send the message or Image file to be displayed to the server. So how do I detect which kind of data is being sent? if it's a plain text or image file and act on the data accordingly. For sending Files
// sendText to the service
void BSocket::sendMessage(const QString &message)
{
QByteArray text = message.toUtf8() + '\n';
socket->write(text);
}
// sendImage to the service
void BSocket::sendFile(const QString &fileName)
{
QImage img(fileName);
img.save(socket);
}
I was building a bluetooth controlled display using Qt and raspberrypi.The raspberrypi will have a bluetooth service running on it and when I connect to the BluetoothServer. The user can choose to either a display a message or upload and display an image. I use QBluetoothSocket to send the message or Image file to be displayed to the server. So how do I detect which kind of data is being sent? if it's a plain text or image file and act on the data accordingly. [b]For sending Files[/b] [code]// sendText to the service void BSocket::sendMessage(const QString &message) { QByteArray text = message.toUtf8() + '\n'; socket->write(text); }
// sendImage to the service void BSocket::sendFile(const QString &fileName) { QImage img(fileName); img.save(socket); } [/code] [b]For Recieving Data[/b] [code]void trialSocket::read_data() { if (socket->bytesAvailable()) { QByteArray ba = socket->readAll(); QMimeType dataType = db.mimeTypeForData(ba); if (dataType.inherits(QString("text/plain"))) { emit displayMessage(QString(ba)); } else if (QImageReader::supportedMimeTypes().contains(dataType.name().toUtf8())) { QImage img = QImage::fromData(ba); emit displayImage(img); } else { qDebug()