简体   繁体   中英

compiling and executing Qt application

Iam starting learning Qt. I have this code snippet and i want to know how i can compile this and excute in gcc. Platform : Linux , gcc compiler

 1 #include <QtGui>
  2 
  3 int main(int argc, char *argv[])
  4 {
  5         QApplication app(argc, argv);
  6         QLabel label("Hello, world!");
  7         label.show();
  8 
  9         return app.exec();
 10 }

That is nicely explained here: http://qt-project.org/doc/qt-4.8/gettingstartedqt.html

It basically boils down to

qmake -project
qmake
make

Also I really recommend to install and use QtCreator: http://qt-project.org/downloads

In your case this is quite simple since you do not have derived any windows, buttons or other widgets.

In general for producing a QT app. you need to do the following:

  1. Compile your annotated headers to meta-object C++ code. You do this by running the meta-object compiler (MOC).

  2. Compile both your source files as well as the source files produced by MOC.

  3. Link all the files together with the QT libraries.

In your case you do not need step 1 and 2, so step three is enough. Just figure out where the necessary libraries reside and link those with the compiled main .

All this is assuming you do not want to use qmake provided with QT, which automatizes the three steps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM