user2138149
user2138149

Reputation: 17170

Default Qt console application doesn't cout "Hello World"... or do anything else

Strange problem this:

I wrote an OpenGL app which compiled in QT but then opened a terminal which sat there doing nothing. As a test I created a new project... the default plain C++ project. It is supposed to:

int main(){
  cout << "Hello World" << endl;
  return 0;
}

But the terminal opens and nothing ever happens. Tried a google search, but didn't find anything. Does anyone know what the problem might be?

Upvotes: 0

Views: 4336

Answers (3)

Alexander
Alexander

Reputation: 11

I have had the same problem. Open "Projects" tab and in "Build & Run" -> "Run" try take off flag from "Run in terminal" then put it back. It looks strange but helped me.

Upvotes: 1

tony
tony

Reputation: 1

use

std::cerr<<

it works for me

Upvotes: 0

Derek
Derek

Reputation: 1114

Try the following code:

#include <QtCore/QCoreApplication>
#include <iostream>

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    std::cout << "hello world" << std::endl;
    return a.exec();
}

From Qt's documentation: The QCoreApplication class provides an event loop for console Qt applications. This class is used by non-GUI applications to provide their event loop. For non-GUI application that uses Qt, there should be exactly one QCoreApplication object. For GUI applications, see QApplication.

Upvotes: 0

Related Questions