Recently do QT project, on the Internet to see a good introductory article, turn around and spare
The original published in the Baidu space, but because of Baidu space repeated revision, the more the worse, so that there is a close may, so transferred to this http://blog.debao.me
QT is a C + + library, QT in the ANSI C + + based on a little expansion.
But domestic seems more impetuous, learn qt many even basic C + + How to compile does not seem very clear. This article discards the constraints of the IDE or Qmake, CMake, and tries to transition from standard C + + compilation to Qt compilation in a few examples.
This article is all about the basics, perhaps, as long as you use C + + Qt, regardless of which tool (Qmake, CMake, Boost.build, Qtcreator, vs2008, Eclipse 、...), the content of this article is to be understood ( We don't compile the QT program directly with the C + + compiler, even though we actually write the program.
If you're afraid of the command line, you might want to take a look at the first example of this GCC beginner I've sorted out. A simple console program
A very simple example, no use to QT extension: (that is, this is a common C + + program)
#include <QtCore/QCoreApplication>
#include <QtCore/QDebug>
int main (int argc, char** argv)
{
qcoreapplication app (argc, argv);
Qdebug () << "Hello qt!";
App.exec ();
}
We all know that compiling a C + + program is nothing more than compile preprocessing, compile, link compiler preprocessor: header file path and necessary macro compiler: Some compiler parameter linker: Some link parameters and the library g++ to link
Simple one-line command to generate Main.exe (under Linux, generate executable program main)
g++ Main.cpp-dqt_core_lib-ie:\qt\4.7.0\include-o Main-le:\qt\4.7.0\lib-lqtcore4
Single line command, very simple:-I specify header file path-l Specify library file path-L Specify required library-D to define the necessary macros (in fact, this small program, this macro is also unnecessary)-O Specify the generated executable file name cl
Simple line command to generate Main.exe
CL Main.cpp-id:/qt/4.7.0/include-dqt_core_lib-femain-link-libpath:d:/qt/4.7.0/lib QtCore4.lib
It's still simple.------Define the necessary macro-fe specify the executable file name-link the linker parameter-libpath library file path example two: simple GUI program
This time a little more complex, not a single console program, but a simple GUI program
Main.cpp
#include <QtGui/QApplication>
#include "widget.h"
int main (int argc, char** argv)
{
Qapplication app (argc, argv);
Widget W;
W.show ();
return app.exec ();
}
Widget.h
#include <QtGui/QWidget> class Widget:public Qwidget {public: