When I try to compile the program at the bottom this is what I get.

-> qtprogram.cpp:1:24: fatal error: QApplication: No such file or directory

I got this code from a C++ QT book and I'm compiling this on Linux with this command.

-> g++ -g -Wall "${ARG}" -o "${ARG:: -4}"

#include <QApplication>
#include <QLabel>

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    QLabel *label = new QLabel("Hello Qt!");
    label->show();

    return app.exe();
}

The command line used to compile the program looks completely incorrect.

When using QT, the best bet is to use qmake, I think it comes with QT when you download the QT development files, but it might be a separate package..... Been a long while since I installed it!

To use qmake: Open up a terminal, navigate to the directory which contains the code for your project and use qmake to create a project for your program.
qmake -project
This will create a file called xxxxx.pro << where xxxxx is the name of the directory your code resides in.
Next run qmake on the generated project file to generate a Makefile:
qmake xxxxx.pro

Finally run the make command to build your application.

BTW: Unless I am mistaken, Line 10 of the example program should be return app.exec();

The file named QApplication. Your compiler can't find it.

First check that you did install the QT libraries, and check where that header file was installed to. When you find it, ensure it's on your standard g++ include path. If it isn't, you'll need to add it to the g++ command line.

Don't forget to link to the QT libraries in your compile command. At least with -lQtCore -lQtGui and mroe as required.

The problem is that the QT headers get installed to a bunch of subfolders in /usr/include/qtx/ << where x is the version of QT that is installed. The QApplication and QLabel headers are in the QtGui subfolder.

Because the headers included in the program (e.g. #include <QApplication>) are not on the actual standard system include path (they are a couple of subfolders in), the program will not compile correctly unless g++ is given the correct paths for the header files.
It's the same story for linking with the QT libs.

qmake is the best way to compile QT programs on the command line IMHO. It will generate a Makefile for you and will take care of creating all of the appropriate settings for g++. Far quicker and easier than doing it manually!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.