How clear screen in QT console?

2019-05-04 00:31发布

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();
}

3条回答
劳资没心,怎么记你
2楼-- · 2019-05-04 00:52

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
查看更多
迷人小祖宗
3楼-- · 2019-05-04 01:01

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.

查看更多
We Are One
4楼-- · 2019-05-04 01:12

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.

查看更多
登录 后发表回答