Example Qt Chat Program
July 9th, 2009A few months ago I gave a presentation to the BYU Unix Users Group on Qt GUI development. During the meeting, we created a simple chat room program called chatterbox. At the time I promised to post my source code with comments, a promise on which I am now making good.
Here is the code. Instructions for building and running it are below:
The client source code (chatterbox.zip)
The server source code (chatterboxd.zip)
Build Instructions
You’ll need to install Qt for your operating system, at least version 4.3 or newer. Make sure “qmake” is in your path. On Windows, you’ll also want Visual Studio 2008 Express. Then, download and unzip the two zip files above. I’ll wait here while you do that.
Building the Server
- Open your favorite terminal (on Windows, use “Qt command prompt” in the start menu)
- cd into the chatterboxd directory
- Run qmake (you should see no output if it suceeds)
- Run make (or nmake on Windows — it will produce a lot of output and hopefully run error free)
- Run ./chatterboxd (or debug\chatterboxd.exe on Windows)
- It should print Ready when it’s ready to go.
Building the Client
Build the client the same way. Note, it’s the chatterbox (no “d” on the end) directory.
What it Looks Like
Here’s what the client looks like when you run it:


Getting Help
If you can’t get this to build or are running into some other problem, just leave a comment below, and I’ll get to it as soon as possible.
September 10th, 2009 at 10:19 pm
Hi,
the client chat what you have develop is multi casting and i want to change it to uni casting.
please help me out.
Thanks a lot.
September 21st, 2009 at 9:06 pm
I have the program up and running but I cant login=(
September 21st, 2009 at 10:51 pm
Joan, did you remember to start the server, and did you type “localhost” into the client login form?
awanish: This is a chat room application, not an instant messenger. It could be modified to be an instant messenger. You would have to modify the server to keep a map of QTcpSockets to usernames (QStrings), and then each client would have to send the username along with each message they want to send. The server could then route the messages appropriately. But seriously, this is just an example program, and if you want instant messaging, I strongly recommend something like Jabber.
March 29th, 2010 at 3:02 am
Very good and informative example, I found it very usefull.
August 2nd, 2010 at 2:04 am
Dave, thanks for answering my e-mail, as you said by adding
connect(client, SIGNAL(disconnected()), client, SLOT(deleteLater()));
to ChatterBoxServer::incomingConnection(int socketfd) function we can fix a memory leak.