0

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 }
3
  • 1
    Isnt Qt a c++ framework? Commented May 15, 2012 at 8:56
  • You do have the Qt Framework installed? You need more than just the g++. Commented May 15, 2012 at 9:12
  • @HWende: For this simple application only g++ as well as the QT-libraries and headers are needed. The full framework (i.e. resource compiler, meta-object compiler etc) are only needed for more advanced features. However it is good to get to know the toolchain already when starting simple (most apps will become more complicated later). Commented May 15, 2012 at 9:15

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

2 Comments

thanks for guidance pls explain where the executable is ...i have done make but i cudn't find executable.
Then something went wrong. Can you post the output you got for all three commands?
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.