Difference between revisions of "Qt4/Qt-Creator Hello World Console Mode"
(→Steps) |
|||
Line 26: | Line 26: | ||
* Pick Qt4 Console Application | * Pick Qt4 Console Application | ||
<center> | <center> | ||
− | [[Image:QtCreatorNewConsoleAppProject.png| | + | [[Image:QtCreatorNewConsoleAppProject.png|400px]] |
</center> | </center> | ||
+ | |||
+ | * Pick a name for the project directory, say, '''helloWorld_console''' | ||
+ | * Pick a full path for the directory, say, '''/Users/yourName/Qt4/''' | ||
+ | * Accept the default module list | ||
+ | * click '''Done''' | ||
+ | * You have a new project with a '''main.cpp''' file and a '''helloWorld_console.pro''' file. | ||
+ | |||
+ | =main.cpp= | ||
+ | |||
+ | * Simply edit the code as follows: | ||
+ | |||
+ | <source lang="c++"> | ||
+ | #include <QtCore/QCoreApplication> | ||
+ | #include <QDebug> | ||
+ | |||
+ | int main(int argc, char *argv[]) | ||
+ | { | ||
+ | QCoreApplication a(argc, argv); | ||
+ | qDebug() << "hello world!" << endl; | ||
+ | //return a.exec(); | ||
+ | } | ||
+ | |||
+ | </source> | ||
+ | |||
+ | =Running the program= | ||
+ | |||
+ | ==Running from inside Qt Creator== | ||
+ | |||
+ | * Simply type Apple-R to run the program. | ||
+ | * Verify that you get an output in the '''Application Output''' window. | ||
+ | |||
+ | hello world! | ||
+ | |||
+ | ==Running from the Terminal== | ||
+ | |||
+ | * Open a terminal window, and '''cd''' to the directory containing the project, and run the newly created file: | ||
+ | |||
+ | $: '''cd /Users/yourName/Qt4/helloWorld_console''' | ||
+ | $: '''ls ''' | ||
+ | Makefile helloWorld_console.pro main.o | ||
+ | helloWorld_console* main.cpp | ||
+ | |||
+ | $: '''./helloWorld_console''' | ||
+ | hello world! |
Revision as of 21:04, 1 June 2010
--D. Thiebaut 01:49, 2 June 2010 (UTC)
Setup
We assume that you have installed Qt Creator and Qt 4 on your Mac (or Windows/Linux platform).
Steps
- Start Qt Creator
- File/New File or Project
- Pick Qt4 Console Application
- Pick a name for the project directory, say, helloWorld_console
- Pick a full path for the directory, say, /Users/yourName/Qt4/
- Accept the default module list
- click Done
- You have a new project with a main.cpp file and a helloWorld_console.pro file.
main.cpp
- Simply edit the code as follows:
#include <QtCore/QCoreApplication>
#include <QDebug>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
qDebug() << "hello world!" << endl;
//return a.exec();
}
Running the program
Running from inside Qt Creator
- Simply type Apple-R to run the program.
- Verify that you get an output in the Application Output window.
hello world!
Running from the Terminal
- Open a terminal window, and cd to the directory containing the project, and run the newly created file:
$: cd /Users/yourName/Qt4/helloWorld_console $: ls Makefile helloWorld_console.pro main.o helloWorld_console* main.cpp
$: ./helloWorld_console hello world!