Nick
Nick

Reputation: 23

Normal C++ code in Qt doesnt build and run

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.

Upvotes: 2

Views: 1416

Answers (1)

Jacinda
Jacinda

Reputation: 5072

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!

Upvotes: 2

Related Questions