程序开启Linux之旅:使用Qt搭建聊天程序(linuxqt聊天)

Life would be incomplete without communication, that’s why chat applications play an important role in our daily life. Protocols like XMPP, IRC and others exist, having many libraries and tools to assist us in the development of applications, but it is much more easier to have something abstracted, an even ready to use implementation, giving us a head start. But, why implement an application from “zero” when we can have something beautiful and functional?

So, let’s start our journery!

Among the many good tools, we have Qt. It provides us an easy-to-use framework for understanding and developing multi-platform applications. It is a very helpful tool that abstracts us enough of the underlying concepts of application development; in this way, it gives us enough confidence to develop our own projects with successful outcomes.

Now, let’s see how we can create a QT project:

First, we create the project with qmake:

mkdir chatsample

cd chatsample

qmake -project

We create the main module with a few configurations:

QT += network

CONFIG += c++11

Our app provides to users a graphical interface. We can add the Qt GUI module with:

QT += widgets

now, we must create a main.cpp for the main method and the whole application logic:

#include

#include “mainwindow.h”

int main(int argc, char *argv[])

{

QApplication a(argc, argv);

MainWindow w;

w.show();

return a.exec();

}

We are now almost ready to build the project, but first we must include the gui logic and other stuff, like:

#include

#include “mainwindow.h”

#include “xmppclient.h”

int main(int argc, char *argv[])

{

QApplication app(argc, argv);

XMPPClient client;

MainWindow window(client);

window.show();

return app.exec();

}

Finally, we run qmake:

qmake && make

Now, our project is ready to run with connected users. The only thing left is distributing the binary!

So, let’s begin our journey with Qt. With this tool, we have an easy way to create applications with a modern graphical interface. It is time to start building and distributing our projects. The sky is the limit!


数据运维技术 » 程序开启Linux之旅:使用Qt搭建聊天程序(linuxqt聊天)