tags:

views:

2443

answers:

2

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 ?

+3  A: 

Go to Project -> Run settings, and make sure "Run in Terminal" is checked.

BTW:

std::cin >> Name;

is probably not what you want. It will read just a single token (typically only the first name). You should have a look at getline, or the string version.

Ropez
Thanks for your answer. I checked the 'Run in Terminal' checkbox, but now I have this problem when running my app :Cannot start the terminal emulator 'xterm'.Any idea ?
Jérôme
OK, I've never used Qt Creator on Mac, only Linux. 'xterm' is the name of the default terminal emulator on Linux. You probably need to change it to "terminal" or something like that. Again, I'm not familiar with Mac. You find this under Tools -> Options -> Environment.
Ropez
A: 

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 !

Jérôme