Console input with Qt Creator

前端 未结 6 1069
执笔经年
执笔经年 2020-12-03 00:54

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

相关标签:
6条回答
  • 2020-12-03 01:24

    I had the "Cannot start the terminal emulator 'xterm'" problem on Mac and fixed it by going to settings, Environment and clicking the "Reset" button next to the Terminal text field.

    For some reason by default it just said "xterm -e" but after the reset it became an absolute path of "/usr/X11/bin/xterm -e".

    My console app then ran fine.

    0 讨论(0)
  • 2020-12-03 01:38

    Jeromes solution is the proper one. Though I can give you a different alternative. In case you don't want to use X11 (for some reason anyhow) in the same position (QtCreator->Preferences->Environment:General:Terminal) you can give your path to the Terminal application like this: /Applications/Utilities/Terminal.app/Contents/MacOS/Terminal

    Enjoy!

    0 讨论(0)
  • 2020-12-03 01:44

    Solution for Windows.

    In the .pro file add:

    QT -= core gui
    TEMPLATE = app
    CONFIG += console
    

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

    0 讨论(0)
  • 2020-12-03 01:45

    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.

    0 讨论(0)
  • 2020-12-03 01:47

    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 !

    0 讨论(0)
  • 2020-12-03 01:47

    For Mac-based Qt 2.4.0, click on the Project vertical tab, which is located below the "Debug" along the same vertical line as Welcome, Edit, Design. In Target-> Run, make sure "Run in terminal" is checked!

    0 讨论(0)
提交回复
热议问题