Skip to Content
Hands-On GUI Programming with C++ and Qt5
book

Hands-On GUI Programming with C++ and Qt5

by Lee Zhi Eng
April 2018
Intermediate to advanced
404 pages
8h 27m
English
Packt Publishing
Content preview from Hands-On GUI Programming with C++ and Qt5

Implementing chat features

Before we start writing any code, we must first enable the networking module by opening our project file (.pro) and add the network keyword there:

QT += core gui network 

Next, open up mainwindow.h and add the following headers and variables:

#ifndef MAINWINDOW_H 
#define MAINWINDOW_H 
 
#include <QMainWindow> 
#include <QDebug> 
#include <QTcpSocket> 
 
private: 
   Ui::MainWindow *ui; 
   bool connectedToHost; 
   QTcpSocket* socket; 

We set the connectedToHost variable to false by default in mainwindow.cpp:

MainWindow::MainWindow(QWidget *parent) : 
   QMainWindow(parent), 
   ui(new Ui::MainWindow) 
{ 
   ui->setupUi(this); 
   connectedToHost = false; 
} 

Once this is done, the first feature we need to implement is the server connection. Open up ...

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

C++ GUI Programming with Qt 4

C++ GUI Programming with Qt 4

Jasmin Blanchette, Mark Summerfield

Publisher Resources

ISBN: 9781788397827Supplemental Content