Skip to Content
Game Programming Using Qt Beginner's Guide
book

Game Programming Using Qt Beginner's Guide

by Witold Wysota, Lorenz Haas
January 2016
Beginner
512 pages
12h 35m
English
Packt Publishing
Content preview from Game Programming Using Qt Beginner's Guide

Time for action – sending text messages

What is left is now is to describe how to send a chat massage. On hitting return inside the line edit, a local slot will be called that checks whether there is actual text to send and whether m_socket is still connected:

QString message = m_user + ": " + ui->text->text();
m_socket->write(message.toLocal8Bit());
ui->text->clear();

If so, a message is composed that contains the self-given username, a colon, and the text of the line edit. To send this string to the peer, the QTcpSocket::write() server is called. Since write() only accepts const char* or QByteArray, we use QString::toLocal8Bit() to get QByteArray that we can send over the socket.

That's all. It's like writing and reading from a file. For the complete ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Game Programming using Qt 5 Beginner's Guide - Second Edition

Game Programming using Qt 5 Beginner's Guide - Second Edition

Pavel Strakhov, Witold Wysota, Lorenz Haas
Programming with Qt, 2nd Edition

Programming with Qt, 2nd Edition

Matthias Kalle Dalheimer

Publisher Resources

ISBN: 9781782168874Supplemental Content