Difference between revisions of "Qt4/Qt-Creator Hello World Console Mode"

From dftwiki3
Jump to: navigation, search
(Created page with '--~~~~ ---- {| | width="40%" | __TOC__ | <bluebox> right | 80px <br /> <br /> This tutorial will introduce you to the Hadoop Cluster in the Computer Sc…')
 
 
(8 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
--[[User:Thiebaut|D. Thiebaut]] 01:49, 2 June 2010 (UTC)
 
--[[User:Thiebaut|D. Thiebaut]] 01:49, 2 June 2010 (UTC)
 
----
 
----
 +
<div style="text-align:right;">
 +
<google1 style="2"></google1>
 +
</div>
 +
 
{|
 
{|
 
| width="40%" |  __TOC__
 
| width="40%" |  __TOC__
Line 9: Line 13:
 
<br />
 
<br />
  
This tutorial will introduce you to the Hadoop Cluster in the Computer Science Dept. at Smith College, and how to submit jobs on it.
+
This tutorial illustrates how to use Qt Creator to create a simple console-mode "hello world" application on a Mac running OS X.
 
 
The setup of the cloud cluster is fully documented [http://cs.smith.edu/classwiki/index.php/CSC352_Hadoop_Cluster_Howto here].
 
 
 
The list of Hadoop/MapReduce tutorials is available [[Hadoop/MapReduce Tutorials | here]].
 
  
 
<br />
 
<br />
Line 19: Line 19:
 
</bluebox>
 
</bluebox>
 
|}
 
|}
 +
 
=Setup=
 
=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
 +
<center>
 +
[[Image:QtCreatorNewConsoleAppProject.png|400px]]
 +
</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:
 +
<br />
 +
<br />
 +
<source lang="cpp">
 +
#include <QtCore/QCoreApplication>
 +
#include <QDebug>
 +
 +
int main(int argc, char *argv[])
 +
{
 +
    //QCoreApplication a(argc, argv);
 +
    qDebug() << "hello world!" << endl;
 +
    //return a.exec();
 +
}
 +
 +
</source>
 +
 +
<br />
 +
 +
=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!
 +
 +
=Variants=
 +
 +
Here are several other variants of the main program.
 +
 +
==Variant #1==
 +
<br />
 +
<br />
 +
<source lang="cpp">
 +
#include <iostream>
 +
 +
int main()
 +
{
 +
  std::cout << "\nHello World!\n";
 +
}
 +
 +
</source>
 +
 +
<br />
 +
 +
==Variant #2==
 +
 +
<br />
 +
<br />
 +
<source lang="cpp">
 +
#include <QTextStream>
 +
 +
int main()
 +
{
 +
  QTextStream out(stdout);
 +
  out << "\nHello World!\n";
 +
}
 +
</source>
 +
<br />
 +
<br />
 +
 +
[[Category:Tutorials]][[Category:C++]][[Category:Qt]]

Latest revision as of 08:05, 21 June 2011

--D. Thiebaut 01:49, 2 June 2010 (UTC)


QtCreator.png



This tutorial illustrates how to use Qt Creator to create a simple console-mode "hello world" application on a Mac running OS X.



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

QtCreatorNewConsoleAppProject.png

  • 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!

Variants

Here are several other variants of the main program.

Variant #1



#include <iostream>

int main()
{
  std::cout << "\nHello World!\n";
}


Variant #2



#include <QTextStream>

int main()
{
   QTextStream out(stdout);
   out << "\nHello World!\n";
}