Tutorial :Normal C++ code in Qt doesnt build and run



Question:

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.


Solution:1

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!


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »