How clear screen in QT console?

╄→гoц情女王★ 提交于 2019-12-22 06:56:08

问题


I need clear QT console. What is the comand?

main.cpp:

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    cout<<"How delete this?";
    //system("CLS")?
    return a.exec();
}

回答1:


You can execute:

QProcess::execute("CLS");

This will of course only work on Windows. On Linux/Unix-ish systems, you'll need to do:

QProcess::execute("clear");

If all you need to do is clear the screen, these things will work. However, if you're trying to build a more sophisticated text-based interface (where certain lines are fixed, or if you want to draw some progress indicators or the like), you'll need something more sophisticated.

  • On Linux there's ncurses: http://www.gnu.org/software/ncurses/
  • On Windows, there's a curses port call PDCurses: http://pdcurses.sourceforge.net/. This will let you run nearly the same code as ncurses. If you're only focused on Windows, you can look at Windows' Console API: http://msdn.microsoft.com/en-us/library/ms682073%28VS.85%29.aspx



回答2:


On Windows, one should use

QProcess::execute("cmd /c cls");

Because plain cls seems not to work in an application.

On Linux, as stated above

QProcess::execute("clear");

should work.




回答3:


The other answers are problematic due to introducing race conditions.

This will work better: (Tested on Ubuntu. Windows, I dont know.)

printf("\033[2J"); // Clear Screen
printf("\033[3J"); // Clear Scrollback


来源:https://stackoverflow.com/questions/20028213/how-clear-screen-in-qt-console

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!