Linux Step By Steps

QT Hello World


From: robin@nextwavesystems.com
tested on COL OpenLinux 2.3 with glibc 2.13

If you don't already have QT installed you'll have to go to the following link to get the api.
http://www.trolltech.com/products/download/freelicense/qtfree-dl.html
This document assumes that you already have it installed. ;-)
  1. Find out where the qt api is on your system:
       locate qt | more ( you may have to run updatedb first if you've just installed the qt api )
    This should show you ( Mine was in /usr/lib/qt/ ).

  2. Edit the following bash script to reflect where your qt is installed and save it as compile.sh:

    #! /bin/bash
    #############################################
    #
    # A script to compile qt programs. To compile,
    # enter: ./compile cpp_name without the '.cc'.
    # To run the program: ./name [ -style=windows||platinum ]
    #
    #############################################

    QTDIR="/usr/lib/qt/";
    CPP_FILE=$1;

    ########## COMPILE CODE HERE ##############

    g++ -c -I${QTDIR}/include $CPP_FILE.cc;
    g++ -o $CPP_FILE $CPP_FILE.o -L${QTDIR}/lib -lqt;

  3. Make sure the permissions are set:
      chmod 711 compile.sh (or whatever you deem appropriate)

  4. In the same directory as your compile.sh script, create a file named hello.cc with the following:

    #include <qapplication.h>
    #include <qpushbutton.h>

    /**** Simple QT Hello ****/

    int main(int argc, char **argv)
    {
         QApplication app(argc, argv);
         QPushButton button("hello world", 0);
         button.resize( 100, 30 );
         app.setMainWidget(&button);
         button.show();
         return app.exec();
    }

  5. Run the the compile script: ./compile hello
  6. Run the program with: ./hello
  7. Also try the following arguments: ./hello -style=windows and ./hello -style=platinum
  8. To learn more about qt look for their tutorial (Mine was in /usr/lib/qt/html/tutorial.html.
    It's a 14 step tutorial that's pretty good at getting you up to speed with the api. Good luck!
&#0;