mathematician1975
mathematician1975

Reputation: 21351

Can Qt be used to write a command line only application?

I have been looking into the use of Qt for C++ developing applications on Linux and have read through most of the book "C++ GUI programming with Qt4". This is great for applications that need a front end, but now I have a requirement to write a C++ command line only application but using some of the Qt networking and socket classes. It has to be command line only as it will run on a host machine that runs command line only install of Ubuntu. In my book I can find absolutely no reference at all to going down this route - everything is described with GUI in mind.

Basically all I need is a yes/no answer (although a pointer to how to start would also be very welcome) as to whether I can use Qt to create a command line only application?? Many thanks.

Upvotes: 0

Views: 605

Answers (1)

rubenvb
rubenvb

Reputation: 76795

Yes, you will need this in your qmake pro file:

CONFIG += console
QT -= gui

which will link only to QtCore, and this essential main code:

#include <QtCore/QCoreApplication>

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    return a.exec();
}

There are several other Qt libraries you can use, like QtNetwork, because they do not depend on QtGui. Check the documentation to find out more.

Upvotes: 6

Related Questions