Qt Creator, ncurses and Linux

This post explains how to configure Qt Creator for ncurses. This tutorial was done with the following software versions:

  • Ubuntu 14.04 LTS
  • Qt Creator 3.0.1
  • Qt 5.2.1

First, install the ncurses package for development :

sudo apt-get install libncurses5-dev

Create a new Qt project, for example a “Qt Console Application” project.
In the .pro file of the project, add the following line to specify to the compiler it has to use the ncurses library:

LIBS += -lncurses

To avoid the following error message : “Error opening terminal: unknown.”, add a variable in the run environment of Qt. Project -> Run -> Run environment -> add. Add a variable named TERM and set it of xterm:


You environment should be ready for ncurses. You can check your configuration with the following code:

// https://www.lucidarme.me
// Include the ncurses library

int main()
    // Initialize ncurses (read terminal configuration)
    // Initiliaze color mode and create a color pair
    init_pair(1, COLOR_WHITE, COLOR_BLUE);

    // Display colorized pair
    printw("This should be printed in white with a blue background!\n");

    // Display uncolorized text
    printw ("Press a key to exit\n");

    // Update screen

    // Wait for a key before exiting

    // Restore initial terminal configuration

Display should look like this:

Leave a Reply

Your email address will not be published. Required fields are marked *