Как определить тип данных или файла, отправляемого в QBluetoothSocket?C++

Программы на C++. Форум разработчиков
Ответить
Гость
 Как определить тип данных или файла, отправляемого в QBluetoothSocket?

Сообщение Гость »


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);
}
For Recieving Data

Код: Выделить всё

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() 

Источник: [url]https://stackoverflow.com/questions/78132913/how-to-detect-the-type-of-data-or-file-being-sent-in-qbluetoothsocket[/url]
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C++»