tags:

views:

189

answers:

1

Hello. I am using Qt under linux, if it matters. I ran successfully under Geany (a simple c++ compiler) the following:

//my first program in C++ Hello World!
#include <iostream>
using namespace std;
int main ()
{cout << "Hello World!";
  return 0;}

I opened Qt source file and copied the exact same code and i can't build or run.

Thank you for your responses to this simple problem.

+1  A: 

If you did what I think you did, you didn't open this as a project, which is the only place where you can build and run (I think).

Try the following.
- Open Qt Creator.
- Go to File->New File or Project
- At the bottom, select "Qt4 Console Application"
- Select a location; it might be nice to create a folder called "hello_world" or something to store the project in.
- A new project will have been created. Copy over the main.cpp file in sources with your code. My code looked like this:

#include <iostream>
using namespace std;

int main()
{
    cout << "Hello World!\n";

    return 0;
}

Hit "Build All"
Hit "Run"

This worked for me. Hope this helps!

Jacinda S
Thanks, it worked. However, i dont get a new window popping up. when i hit "run" this is all i get http://img515.imageshack.us/img515/5808/screenshotghl.pngI also tried to run the .exe file, still nothing happens.I suppose it is some minor mistake I am making.Thank you once again
Nick
This code is displaying "Hello World !" into a console and exit. So when you launch it you will see the console appar and disappear immediately.
Patrice Bernassola
So it exits by itself? I dont see it appear and disappear. Probably it happens too fast? Can I tell it to stay and exit only when i close the window?
Nick
This particular project won't show a window because it was a console app. If you want something that uses a GUI, create a Qt4 GUI app instead of a console app and then follow along here: http://doc.trolltech.com/4.3/tutorial-t1.htmlI'm not sure about the executable; when I run it at the command line it outputs correctly.Also, a minor note, but you wrote /n instead of \n so it's outputting the full string instead of writing a newline.
Jacinda S
thank you, i will take a look
Nick
No problem. Good luck!
Jacinda S