Console input with Qt Creator

Jérôme picture Jérôme · Aug 31, 2009 · Viewed 58.8k times · Source

I'm developping a very simple app on my Mac using QtCreator.

It's a console application and I want the user to enter its name, and then I display his name. Here is the code :

#include <iostream>

int main(int ArgC, char* ArgV[])
{
    char Name[1000];

    std::cout << "Type your name : ";
    std::cin >> Name;

    std::cout << "Hello " << Name << "\n";
    return 0;
}

When running this app with QtCreator, the string "Type your name :" is displayed in the 'Application Output' tab. But if I type some text and press the enter key, nothing is happening.

What's wrong ?

Answer

J&#233;r&#244;me picture Jérôme · Jan 22, 2010

I found a solution. With Qt Creator 1.3.0 (on Mac OS X), here is what I had to do :

  • Project->Run settings, check "Run in Terminal" (thanks Ropez)
  • Qt Creator->Preferences : Environnement : General : Terminal : I had to put the whole path to XTerm. For my config, I had to put /usr/x11/bin/xterm -e.

Now, everything is working fine !